Consider the following code:
MyClass.prototype.my_func = function () { this.x = 10; $.ajax({ // ... success: function (data) {
You can make usage of Function.prototype.bind for that:
Function.prototype.bind
MyClass.prototype.my_func = function () { this.x = 10; $.ajax({ // ... success: function (data) { alert(this.x); }.bind(this); }); }
Now the parent context variable is also bound to the anonymous function.