Inside func , this refers to an instance of Child .
Child.prototype.__proto__ = new Parent;
The Child prototype is assigned an instance of Parent . Therefore, when ch.func() is called, func() is in the Child prototype chain, but is called in the context of ch , which is an instance of Child
self still refers to an instance of Parent that does not have an attribute a
For additional illustration:
var p = new Parent(); // this.a is undefined because this is an instance of Parent p.func(); // undefined undefined
Aditya manohar
source share