14km

Jan 13

Researching how javascript prototype inheritance works. Methods defined in the constructor are copied for each instance, whereas methods on the prototype are shared.

When you set the prototype of a “class”, you need to reset the constructor:

B.prototype = new A;                // Define sub-class
B.prototype.constructor = B;

And to call the parent class’s constructor:

A.call(this);