[jQuery] event handler variable scope in classes
I'm a bit of a jQuery newbie, trying to convert some existing class
files to a jQuery structure. I have a class like this:
function testClass(){
this.foo = 100;
this.init();
}
testClass.prototype = {
init: function(){
var instance = this;
$('a', instance).click(function(){
instance.doSomething(instance.foo);
});
},
doSomething: function(text){
alert(text);
}
}
Is setting up a local var that references the class instance in each
prototype function where another class property or function needs to
be referenced the only solution? Is there a better way?
Thanks,
Steve