I've read some articles about V8's hidden classes. However, I still have a few questions in my head:
If, let's say, there are two objects:
var a = { }
a.x = 5
a.y = 6
var b = { }
b.y = 7
b.x = 8
Do they end up with the same hidden class or separate just because one went 0 + x + y
and the other 0 + y + x
? As I understood, they get different classes but just wanna make sure I got it.
Then, we have this case:
function Point(x, y) {
this.x = x
this.y = y
}
var a = new Point(7, 8)
var b = { }
b.x = 6
b.y = 8
var c = {
x: 8,
y: 9
}
var d = {
y: 9,
x: 80
}
Do we end up with the same hidden class? I might guess that a
, b
and c
do but d
doesn't. Unless there is some sorting done on such object expressions (similarly to array's short declaration being analysed for the type).
Finally, we have this:
function PointA(x, y) {
this.x = x
this.y = y
}
var a = new PointA(7, 8)
function PointB(x, y) {
this.x = x
this.y = y
}
var b = new PointB(7, 8)
It is sorta similar to the second case. These objects seem the same except that their origin (instanceof...
) is different. However, do there objects end up with the same hidden class?