super not defined, obviously this will not work.
You might want to try:
Sub.prototype.log = function() { console.log("sub log"); Base.prototype.log.call(this); }
Another way is to use the following method to inherit classes:
function extend(Child, Parent) { var F = function() { }; F.prototype = Parent.prototype; Child.prototype = new F();
So here is an example:
// .. extend(Sub, Base); Sub.prototype.log = function() { console.log("sub log"); this.super.log.call(this); }
In the case of ES6 :
class Base { constructor(msg) { this.msg = msg; } log(){ console.log("base log: " + this.msg); } } class Sub extends Base { constructor(msg) { super(msg); } log() { console.log("sub log"); super.log(); } } var sub = new Sub('hi'); sub.log();
source share