Created
May 1, 2012 19:24
-
-
Save tauren/2570687 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Bind all of an object's methods to a specific context. Useful for ensuring that | |
// all callbacks defined on an object belong to it. | |
var context = function(obj, ctx) { | |
var funcs = Array.prototype.slice.call(arguments, 2); | |
if (funcs.length == 0) funcs = _.functions(obj); | |
_.each(funcs, function(f) { obj[f] = _.bind(obj[f], ctx); }); | |
return obj; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment