What is going on here?
var x = {length:3, '0':'foo', '1':'bar','2':'f', splice:function(){}}
This actually creates an array:
["foo", "bar", "f"]
Where is the documentation for this structure syntax?
It's also smart:
changing to: (notice 0 , 1 , 3)
var x = {length:3, '0':'foo', '1':'bar','3':'f', splice:function(){}}
will mess up the array and it will be:
["foo", "bar", undefined × 1]
Also, removing the splice function:
var x = {length:3, '0':'foo', '1':'bar','2':'f'}
yields: (regular object)
Object
0: "foo"
1: "bar"
2: "f"
length: 3
__proto__: Object
So I have two questions:
What is this structure?
length , element , spliceSay I have
['john','paul','yoko']and now I want to create the objectvar x = {length:3, '0':'john', '1':'paul','2':'yoko', splice:function(){}}How would I do this?
x.constructorgivesfunction Object() ....Object.prototype.toString.apply(x)="[object Object]"