In the below visualisation,
There are two array objects(cars
& bikes
) that are created with below syntax,
var cars = new Array("Saab", "Volvo", "BMW");
var bikes = ["Honda", "Yamaha"];
whose [[Class]]
property value is Array
.
In addition, we also have Array.prototype
, which is fully functional array, as shown below,
> Object.prototype.toString.call(Array.prototype);
"[object Array]"
> Array.prototype[0] = "Volvo";
"Volvo"
> Array.prototype[1] = "BMW";
"BMW"
> Array.prototype.length;
2
Generally, When you put something on the prototype
, every instance of the object shares the same properties.
Question:
With length
property as member, What is the idea behind Array.prototype
being fully functional array?
array
not fully functional?" And I think the answer to that is self-evident: for the same reasons that you split the functionality of a class into an abstract class and a class that inherits from it. – Robert Harvey Dec 6 '15 at 16:00Array.prototype
is more thanObject
? More in the sense of providing facility to store elements. – overexchange Dec 6 '15 at 17:29[42]
is essentially the same thing as{ "0": 42 }
but with a different prototype and that funkylength
property. – Ixrec Dec 6 '15 at 17:35length
property that get incremented for each property stored in the object. This is where I say thatArray.prototype
is fully functional array. – overexchange Dec 7 '15 at 0:18