Skip to content
Advertisement

Javascript inheritance and method overriding

Assume I have a class like this:

JavaScript

From this class I created some other classes which inherit the same prototype but have some added methods. What I want to do is being able to define a load() method in the sub-classes which first calls the parent method and then execute some code. Something like:

JavaScript

I know there’s no super keyword in Javascript but there must be a way to do this.

Advertisement

Answer

You can simulate it like this:

JavaScript

Or you can create your own super property like this:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement