I am building an object oriented library in javascript using prototypal inheritance. Similarly to Java and .NET, all of my objects/prototypes will inherit the “Object” object/prototype. I want to know if it is possible to call super object/prototype functions from derived ones?
Consider the following code exmaple:
function Object() {
this.DoAction = function() {
};
};
function CustomObject() {
this.DoAction = function() {
super.DoAction(); //How do I do this in JavaScript?
};
};
JavaScript does not have the direct equivalent of
super.A workaround could be to save the method on the prototype before overriding it, like:
If you are able to use ES5 features, you can use
Object.getPrototypeOfto get the method from the prototype, and thenapplyto execute it with the current object asthis: