Consider this example:
var a = {}
a.b =5
a.hasOwnProperty("b") // return True
a.hasOwnProperty("__proto__") // returns False
If __proto__ itself isn't declared as object's own property then,
- where is this
__proto__property declared ? - how is this property referenced while searching through prototype chain, if it itself is not object's own property ?
The
__proto__property belongs toObject.prototypedeclared inprototypeobject ofObjectand is not own property of objectain your code. That's why it returned false when you did.If you do:
This returns
true, because__proto__is own property ofObject.prototype** Part 2:**
The
__proto__property is a simple accessor property onObject.prototypeconsisting of agetterandsetterfunction. A property access for__proto__that eventually consultsObject.prototypewill find this property, but an access that does not consultObject.prototypewill not. If some other__proto__property is found beforeObject.prototypeis consulted, that property will hide the one found onObject.prototype.That's how it finds its way in the prototype chain.