Consider the following code:
MyClass.prototype.my_func = function () {
this.x = 10;
$.ajax({
// ...
success: function (data) {
alert(this.x);
}
});
}
It doesn't work, since apparently this
is not bound into the closure's execution context. I've been able to work it around by introducing another variable:
var _this = this;
And this works inside the anonymous function. But looks quite ugly to me. Is there some nice way to handle this?