Skip to content

Instantly share code, notes, and snippets.

@seidtgeist
Last active December 18, 2015 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save seidtgeist/5783174 to your computer and use it in GitHub Desktop.
Save seidtgeist/5783174 to your computer and use it in GitHub Desktop.
// Motivation:
//
// I see myself writing this quite often:
f(_.bind(obj.m, obj))
// but I could write:
f(bound(obj, 'm'));
// @evilhackerdude v1
function bound(object, fn) {
return _.bind(object[fn], object);
}
// @raganwald
function bound(object, fn) {
return object[fn].bind(object);
}
// @evilhackerdude v2
function bound(object, fn) {
return function() {
object[fn].apply(object, arguments);
};
}
@raganwald
Copy link

I have some code that can force an arity in allong.es, I use it precisely because I wanted to make sure that everything interoperates with curry and partial application. We could look at whether to "improve" bind such that it preserves length even in older browsers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment