3 ms·
I'm partial to keeping a "bind" function handy. (Function#bind will be in ECMAScript 5, but it's not quite here yet). It's crucial for keeping your sanity when
by jashkenas 16y ago
I'm partial to keeping a "bind" function handy. (Function#bind will be in ECMAScript 5, but it's not quite here yet). It's crucial for keeping your sanity when trying to use "this" with callbacks, Ajax, or async.
var bind = function(func, context) {
var slice = Array.prototype.slice;
var args = slice.call(args, 2);
return function() {
return func.apply(context || {}, args.concat(slice.call(arguments)));
};
};