Don't know if the question's title is too confusing but here I go.
If I got something like:
var Test = function(){
this.foo = a;
}
Test.prototype.init = function() {
$(document).on('change', '.form-control', this.myFunction);
}
Test.prototype.myFunction = function() {
console.log(this.foo);
console.log(this);
}
My understanding is that when printing 'this' in myFunction it would print the execution context of the function that made the call, in this case it'll print the execution context for .on('change' ...). So when printing this.foo since it doesn't exist in that context then undefined will be printed out.
To solve this issue and to access this.foo, I'm doing the following:
Test.prototype.init = function() {
$(document).on('change', '.form-control', (this.myFunction).bind(this));
}
Test.prototype.myFunction = function() {
console.log(this.foo);
console.log(this);
}
I'm binding 'this' to the function call, so this.foo would be printed out which is OK, but my question is, in that case how can I also get access to the execution context for .on('change' ...)??? Meaning, how can I access the 'this' that I had originally access to before the binding?
Thanks