E.g., in this very primitive and simplified piece of code:
function Parent() { }
function Child() { }
Object.setPrototypeOf(Child.prototype, Parent.prototype); // OR: "Child.prototype.__proto__ = Parent.prototype;" (the result is totally identical)
versus:
function Parent() { }
function Child() { }
Child.prototype = Object.create(Parent.prototype);
Then I check these two pieces of code the following way:
console.log(child instanceof Child); // true for both examples
console.log(child instanceof Parent); // true for both examples
console.log(Parent.prototype.isPrototypeOf(child)); // true for both examples
console.log(Child.prototype.isPrototypeOf(child)); // true for both examples
However: checking against the next two lines leads to different results —
console.log(JSON.stringify(Object.getOwnPropertyNames(Child.prototype), null, 2)); // ["constructor"] vs []
console.log(child.__proto__); // a constructor property is shown (on the first place) only in the first case and no constructor property – in the second case
— whereby only in the first case Parent constructor is displayed (see the images attached). What causes this difference?