Skip to content

Instantly share code, notes, and snippets.

@coreh
Created August 2, 2012 01:31
Show Gist options
  • Save coreh/3232301 to your computer and use it in GitHub Desktop.
Save coreh/3232301 to your computer and use it in GitHub Desktop.
bind2
/**
* This function is similar to bind, but the received value of "this"
* gets passed as the first function argument.
*/
function bind2 (fn, _this) {
return function() {
var args = [].slice.call(arguments);
args.unshift(this);
fn.apply(_this, args);
}
}
var f = bind2(function(that, x, y, z) {
this.doSomethingWith(that);
}, this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment