A common JavaScript idiom is to store the value of this
in a variable like me
or self
, and use it in a callback.
This will work, since the callback has access to variables declared in the scope - in other words, the callback forms a closure on self
var greatapp = { start : function(){ var self = this; $.AJAX({ url : 'foo.com', success : function(data){ self.say(data); } }) }, say : function(s){ console.log(s); } }
Adam rackis
source share