In Google Chrom's javascript, objects have a property named __proto__
that points to their prototype (or parent) object.
var foo = {};
console.log(foo.__proto__ === Object.prototype); //returns true
However, this is not true for the Object
object.
console.log(Object.__proto__ === Object.prototype); //returns false
The Object.__proto__
property appears to be an empty method
> console.log(Object.__proto__.toString());
function () {}
Beyond serving as a warning story about relying on javascript features that start outside standard bodies -- what is the Object.__proto__
function?
Based on squint's comments above, I've been able to get to the bottom of this. My unstated, incorrect (and 10+ year) assumption was that the global Object
helper object's prototype object was also the top level "prototype of prototypes" at the top/end of javascript's prototype chain. This is not true.
The Object
helper object and the Function
helper object both have the same parent prototype-object
console.log( Object.__proto__ === Function.__proto__ ); //true
So, the reason Object.__proto__
points to an empty function is -- that empty function is its prototype object for the Object
object. If you want to get to the prototype of prototypes from Object
(without using .prototype
), you need to dig back a bit further.
console.log( Object.__proto__.__proto__ === Object.prototype ); //true
I also put together a quick diagram that maps out the real prototypes of a few of Javascript's lower level helper/constructor objects.
Finally -- I also also discovered Google Chrome has implemented the Reflect
object, which includes a getPrototypeOf
method, which appears to be the same as the Object.getPrototypeOf
method.