I’m reading this post. It defines a simple array:
var myArray = [1, 2];
myArray.push(3);
myArray.reverse();
myArray.pop();
var length = myArray.length;
and then tries (and succeeds) in getting its prototype via Object.getPrototypeOf. However, when I tested this in Firebug and Chrome’s console, I get an empty array. Why?.
However, when I do the same for an object (in this case, the point object defined in the same post), I actually get its prototype.
Chrome’s Developer Tools displays
Array.prototypeas an array, because it suffices the two requirements for this behaviour:.lengthproperty.splicefunctionArray instances have these properties, so you see arrays as actual arrays which is helpful. The problem is that
Array.prototypealso is an array according to Chrome’s Developer Tools because of these rules (which it also is, but it’s not a very helpful visualisation because it shouldn’t have elements).If you evaluate
Object.getPrototypeOf(myArray) === Array.prototype, you’ll gettrue. It’s just Chrome’s Developer Tools that doesn’t displayArray.prototypeas you might expect.