I've created an A
object using the following code:
function A(){
this.one = "one"
this.two = "two"
this[0] = "numeric index"
}
var objs = [];
for (var i=0; i<10;i++){
// create 10 objects to get object size without slack/space for additional properties
objs.push(new A())
}
objs.forEach(function(obj){
obj.extraProperty = "extra"
})
As expected, the DevTools heap snapshot shows the size as 40 bytes:
- 2*8 bytes for the two properties
one
andtwo
- 8 bytes for
extra properties
- 8 bytes for
elements
(numbered properties) - 8 bytes for the hidden class
Based on this explanation of V8 object representation.
However, the heap snapshot also lists __proto__
as a property, but I assume it doesn't add anything to the size of the object.
It is also already accessible as part of the hidden class/Map, so storing an additional reference to it isn't necessary.
Is the __proto__
property just shown for convenience? How is it intended to be used?