In jQuery 1.4 you have a method $.proxy, you can simply write:
bar: function(id) {
$.ajax({
url: "someurl",
success: $.proxy(this, '_updateDiv')
});
},
$.proxy , this, ( ), , , .
bind, ECMAScript Fifth Edition:
bar: function(id) {
$.ajax({
url: "someurl",
success: function(data) {
this._updateDiv(id, data);
}.bind(this)
});
},
, JavaScript ES5, 8- :
if (!Function.prototype.bind) {
Function.prototype.bind = function(){
var fn = this, args = Array.prototype.slice.call(arguments),
object = args.shift();
return function(){
return fn.apply(object,
args.concat(Array.prototype.slice.call(arguments)));
};
};
}