The answer to this question is @Bergi. Here is a detailed answer what happens in case of __proto__
var a = Object.create({}); var b = Object.create(a); b.__proto__===a; //true var c = Object.create(null); var d = Object.create(c); d.__proto__===c; //false..confusion Object.hasOwnProperty.call(d,"__proto__"); //false as expected Object.hasOwnProperty.call(b,"__proto__"); //false ? Object.hasOwnProperty.call(Object,"__proto__"); //false Object.hasOwnProperty.call(Object.prototype,"__proto__"); //true
This means that __proto__ is only present in Object.prototype .
Object.getOwnPropertyDescriptor(Object.prototype,"__proto__") //{enumerable: false, configurable: true, get: ƒ, set: ƒ}
__proto__ is a getter setter that should return an internal reference to the parent object, something like
get __proto__(){return this.hidden_internal_link_to_parent;}
Case b.__proto__ : - b does not have the __proto__ property, so it goes through the [[prototype]] chain to a , then to a parent, and finally to Object.prototype . Object.prototype have __proto__ and it returns the link b parent, which is a .
Case d.__proto__ : - d reference to Object.prototype broken (d --parent → c and c - parent → null). So d.__proto__ undefined. But d has an internal reference to c , which can be accessed by Object.getPrototypeOf(d) .
amit77309
source share