Created
August 2, 2012 01:31
-
-
Save coreh/3232301 to your computer and use it in GitHub Desktop.
bind2
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
/** | |
* 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