Skip to content

Instantly share code, notes, and snippets.

@ryanwilliamquinn
Created July 29, 2014 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanwilliamquinn/6e9194627a1dd6263a15 to your computer and use it in GitHub Desktop.
Save ryanwilliamquinn/6e9194627a1dd6263a15 to your computer and use it in GitHub Desktop.
sorting out function.bind.bind
1. Function.bind.bind(Function.call) = Function.call.bind
2. Function.call.bind(someOtherFn) = someOtherFn.call
3. someOtherFn.call(newThisValue)
First you set up the 'binder' function. Note that 'binder' is not an official term, I just made it up:
var bb = Function.bind.bind(Function.call); // bb ends up as a function: Function.call.bind
then you can use it like so:
var boundfn = bb(someOtherFn); // boundfn is now a function: someOtherFn.call
which is a shortcurt to the equivalent statement:
var boundfn = someOtherFn.call.bind(someOtherFn);
Here is one example of each way of doing it:
var binder = Function.bind.bind(Function.call);
var myfncall2 = binder(myfn);
myfncall2({test: 'this other crap'});
var myfn = function () {console.log("testing: " + this.test)};
var myfncall = myfn.call.bind(myfn);
myfncall({test: 'this crap'});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment