G
Gregor Kofler
How can I access a private variable when replacing a private function,
which originally had access to this variable, with another one? Or is it
just not possible?
Example:
function foo() {
var privateVar = 42;
var privateFunc = function() {
alert(privateVar);
}
return {
replacePF: function(f) { privateFunc = f; }
}
}
var obj = foo();
obj.privateFunc(); // 42
obj.replacePF(function() { alert("The answer is "+privateVar); }
obj.privateFunc(); // privateVar is undefined
Gregor
which originally had access to this variable, with another one? Or is it
just not possible?
Example:
function foo() {
var privateVar = 42;
var privateFunc = function() {
alert(privateVar);
}
return {
replacePF: function(f) { privateFunc = f; }
}
}
var obj = foo();
obj.privateFunc(); // 42
obj.replacePF(function() { alert("The answer is "+privateVar); }
obj.privateFunc(); // privateVar is undefined
Gregor