I have the following code where there are two functions a, c and c is inheriting from a.
function a(){
console.log("constructor-a");
}
a.prototype.fun1 = function(){
console.log("a-fun1");
}
a.prototype.fun2 = function(){
console.log("a-fun2");
}
function c(){
c.super_.call(this)
console.log("constructor-c");
}
c.prototype.fun5 = function(){
console.log("c-fun1");
}
c.prototype.fun6 = function(){
console.log("c-fun2");
}
util.inherits(c,a);
var X = new c();
console.log("X instanceof a", X instanceof a);
console.log("X instanceof a", X instanceof c);
Since c is inheriting from a, the functions of both c and a should be executable from an object of C, however, in this case the outputs are as follows:
X.fun1() --> a-fun1
X.fun2() --> a-fun2
X.fun5() --> TypeError: X.fun5 is not a function
X.fun6() --> TypeError: X.fun6 is not a function
util.inheritsneeds to be called before assignments to the prototype.