How To Call Parent Function in Child Class

1
2
3
4
SubClass.prototype.foobar = function(str) {
BaseClass.prototype.foobar.call(this, str);
console.log("bbb");
};

yea, as simple as that.

Don’t forget sub-class is made of this

1
SubClass.prototype = new BaseClass();

This makes all legit.

Full source view

1
2
3
4
5
6
7
8
9
10
11
12
function BaseClass(){}
BaseClass.prototype.foobar = function(str) {
console.log(str);
};

function SubClass(){}
SubClass.prototype = new BaseClass();
SubClass.prototype.constructor = SubClass;
SubClass.prototype.foobar = function(str) {
BaseClass.prototype.foobar.call(this, str);
console.log("bbb");
};