Last active
August 29, 2015 14:01
-
-
Save ayamflow/387d19a0ae658f0de8b6 to your computer and use it in GitHub Desktop.
bindAll standalone from underscore
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
module.exports = function(obj) { | |
var funcs = Array.prototype.slice.call(arguments, 1); | |
if (funcs.length === 0) throw new Error('bindAll must be passed function names'); | |
funcs.forEach(function(f) { | |
obj[f] = obj[f].bind(obj); | |
}); | |
return obj; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment