Last active
September 19, 2015 00:40
-
-
Save Cfeusier/2a1e2aa90f32850125cb to your computer and use it in GitHub Desktop.
Replacement for underscore's .bindAll function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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