Javascript Class Inheritance For Functions

It’s similar to the call in your inherited constructor. You can access the “super” method still on MyBase.prototype.MySuperFunction (where you assigned it), so use:

MyBase.prototype.MySuperFunction.call(this, arg1);

For a more dynamic approach you even might use Object.getPrototypeOf to get the prototype, but watch out that it works with dynamic inheritance. And if you have many methods that need to call their parent, it can be helpful to alias MyBase.prototype as a super variable which is accessible to all functions on the Child prototype object (see this answer for an example)).

Leave a Comment