Question

So if you look at this fiddle http://jsfiddle.net/r0k3t/z8f2N/1/ you can see that

var me = { fName: "ken", lName: "n" };

console.log(Object.prototype === Object.getPrototypeOf(me));

returns true. Why doesn't

console.log(Object.prototype === me.prototype);

Given that I created the "me" object as an object literal sure enough it's prototype should be Object.prototype and the first line would seem to confirm that.

Was it helpful?

Solution

Object.prototype === me.constructor.prototype; // true

I let you guess now how getPrototypeOf works :-)

Also, the non-standard-yet-but-works-almost-everywhere solution (thanks jAndy):

Object.prototype === me.__proto__; // true
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top