I have a little problem in object programming in javascript
There is a “class” Task, it has several methods, a method containing an asynchronous sending of a request with a help of JQuery ($.ajax). After request is success it’s necessary to perform a particular method (e.g. successFunction) of the class Task.
The problem is, after the query in the body of successFunction it’s impossible to refer to the class using the keyword this, because the context has changed, and this contains a reference to the jquery-object which performs an ajax-request.
What variants to refer to the current Task object inside a function that was not caused directly but externally exist? (For example by an event or ajax)
Normally inside an AJAX event such as the success callback,
thisrefers to the object returned by the$.ajaxcall. You could use thecontextparameter to change the context in the success callback:You could also pass complex objects: