V8 Object takeaway
- Array-indexed properties are stored in a separate elements store.
- Named properties are stored in the properties store.
- Elements and properties can either be arrays or dictionaries.
- Each JavaScript object has a HiddenClass associated that keeps
Element
function Foo() {
this[100] = 'test-100'
this[1] = 'test-1'
this["B"] = 'bar-B'
this[50] = 'test-50'
this[9] = 'test-9'
this[8] = 'test-8'
this[3] = 'test-3'
this[5] = 'test-5'
this["A"] = 'bar-A'
this["C"] = 'bar-C'
}
var bar = new Foo()
for(key in bar){
console.log(`index:${key} value:${bar[key]}`)
}
Property
function Foo2(property_num,element_num) {
for (let i = 0; i < element_num; i++) {
this[i] = `element${i}`
}
for (let i = 0; i < property_num; i++) {
let ppt = `property${i}`
this[ppt] = ppt
}}
var bar2 = new Foo2(20, 10)
Top comments (0)