I want to use this keyword in the callbacks of $.get(). My code structure is
var myObject = {
get: function() {
$.get(server,data,function(data,status) {
this.callback();
});
},
callback: function() {
}
}
I don't want to use myObject.callback(). Is there any way to accomplish using this.callback()?
You can
.bind()the value ofthisto your callback function before passing it to$.get():Of course, that assumes the value of
thiswithin your ownmyObject.get()function is correct, which it would be if you called it with "dot notation" asmyObject.get().Note also that if the only thing your anonymous function does is call the other function then you can bind the other function directly: