I’m coding a JavaScript client to a REST JSON API. Since I don’t want it to depend on any other libraries I’m doing it with vanilla javascript.
Everything have been working great, but I’m having troubles with the inheritance in IE (it works in every other browser). I’m doing it like this;
/**
* BaseClass
*/
api.BaseClass = function(something) {
this.someFunction(something);
};
api.BaseClass.prototype.someFunction = function() {
// Code...
};
/**
* Subclass
*/
api.SubClass = function(something) {
// to make the constructor be called in the base
this.base = api.BaseClass;
this.base(something);
delete this.base;
};
api.SubClass.prototype.__proto__ = api.BaseClass.prototype;
// here be subclass prototypes...
The error occurs when instantiating with new api.SubClass('argument'); The instance didn’t get the function “someFunction”. Could someone guide me on how to correctly do inheritance that works even in IE.
That’s because IE doesn’t support
__proto__.you should do this instead: