I am writing a piece of JavaScript like that:
MyClassA.prototype.method1 = function(){
//here, "this" refers to my instance of MyClassA
$.ajax({
url : "http://foo.com/foo",
success: function(data) {
//OMG! "this" now refers to another object
}
}
});
I need to access to the this element of MyClassA in the success function. In Java, it is possible to use MyClassA.this to refer to the right this instance inside an inner class. Is there a comparable way to do that in JavaScript?
Is
MyClassA.prototype.method1 = function(){
var myClassAThis=this;
$.ajax({
url : "http://foo.com/foo",
success: function(data) {
myClassAThis.method2();
...
}
}
});
the standard way to proceed in such situation?