You'll have to pass the value of "e" to the other function as a parameter. Scoping in JavaScript is determined by the lexical relationship of functions, not the dynamic relationship. Code in a function can see "outwards", and moving out from funcB()
does not encounter a scope with "e" defined. The only symbols visible to code in funcB()
are its own local symbols (p
in this case) and global symbols.
Now, you could explicitly stash a copy of "e" on the object itself as a property:
return function(e) {
window.console.log('k: ' + k); // 'abc'
window.console.log('e: ' + e); // 'def'
that.e = e;
return that.funcB(k);
};
Test.prototype.funcB = function (p) {
window.console.log('p: ' + p); // 'abc'
window.console.log('e: ' + this.e);
}