So I already know a way around this, but I'm curious if there is a better way to handle this call. I should further mention that I'm using Backbone. Here is what I'm trying to accomplish:
loadKey: function() {
$.ajax({
// some settings
success: function(data) {
this.set('key', data.key);
}
});
}
Now obviously this example won't work, because the nested success function is out of the scope of the models this. Here is how I'm currently handling this:
loadKey: function() {
self = this;
$.ajax({
// some settings
success: function(data) {
self.set('key', data.key);
}
});
}
So back to my question. Is this a perfectly acceptable way to handle this? Or is there another way to do this that's considered better?