I have an object that inherit from another one. In the child object, I initialize some instance variables. In the parent object, I have a method that call private functions that use these instance variables.
function objA() {
this.funcA = function() {
alert(this.var);
funcB();
};
function funcB() {
alert(this.var);
};
}
objB.prototype = new objA();
objB.prototype.constructor = objB;
function objB() {
this.var ="hello";
this.funcA();
}
the first alert gives "hello", the second undefined...
I understant that 'this' in javascript is the identity of the object calling the function, not the instance itself... I assume that when calling funcB, i'm in some kind of parent context where the variable does not exists...
I'm a pure javascript newbie, and I can't figure out how to solve that. Of course, I could pass it as agument, but it's not very OOP, and in my project, there are a lot more variables to make availables...
Thanks