The general template is as follows:
A temporary constructor is created that inherits from the prototype of the parent constructor. Then the prototype of the child constructor is installed in the instance of the temporary constructor.
function inherits(Child, Parent) { var Tmp = function() {}; Tmp.prototype = Parent.prototype; Child.prototype = new Tmp(); Child.prototype.constructor = Child; }
Inside the child constructor, you need to call the parent constructor:
function Child(a, b, c) { Parent.call(this, a, b); } inherits(Child, Parent);
Inside this call to the this function, this will refer to the new object that is created when new Child() is called, therefore, any initialization is done inside Parent , it is applied to the new object that we are passing.
source share