Answer by @Bergi is correct. Here is in-depth answer what is happening 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
Which means __proto__
is only present in Object.prototype
.
Object.getOwnPropertyDescriptor(Object.prototype,"__proto__")
//{enumerable: false, configurable: true, get: ƒ, set: ƒ}
__proto__
is a getter setter which should return internal link to object parent something like
get __proto__(){return this.hidden_internal_link_to_parent;}
Case b.__proto__
:- b
doesn't have __proto__
property so it goes through [[prototype]]
chain to a
, then to a
's parent and at last to Object.prototype
. Object.prototype
have __proto__
and it returns link of b
's parent which is a
.
Case d.__proto__
:- d
's link to Object.prototype
is broken (d --parent-->c and c--parent-->null). So d.__proto__
is undefined. But d
have internal link to c
which can be accessed by Object.getPrototypeOf(d)
.