I research functional inheritance in javascript. According the article I have read I have wrote the code:
function Base(){
var enableVar = true
this.enable = function(){
console.log("enable");
enableVar = true;
}
this.disable = function(){
console.log("disable");
enableVar = true;
}
}
function Child(){
Base.call(this);
}
new Child().enable();
this code works properly and I see message in console.
but I don't understand row:
Base.call(this);
for me it is Base
function invocation with this
replaced with this
thus it is same with Base();
But looks like my state is wrong. I see error:
VM898:62Uncaught TypeError: (intermediate value).enable is not a function(…)
Please clarify difference for me.
UPDATE
function funcB(){
return this.a;
}
function funcA(){
this.a = 2;
return funcB();
}
alert(funcA());
this code alerts 2 although I invoke funcB
like funcB();
I really don't understand difference