Skip to content

Instantly share code, notes, and snippets.

@Cfeusier
Last active September 19, 2015 00:40
Show Gist options
  • Save Cfeusier/2a1e2aa90f32850125cb to your computer and use it in GitHub Desktop.
Save Cfeusier/2a1e2aa90f32850125cb to your computer and use it in GitHub Desktop.
Replacement for underscore's .bindAll function
function bindAll(obj) {
for (var key, i = 1, length = arguments.length; i < length; i++) {
key = arguments[i];
obj[key] = bind(obj[key], obj);
}
return obj;
}
function bind(func, ctx) {
var ctxArgs = Array.prototype.slice.call(arguments, 2);
return function() {
var allArgs = ctxArgs.concat(Array.prototype.slice.call(arguments));
return func.apply(ctx, allArgs);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment