Last active
August 29, 2015 14:15
-
-
Save yellownoggin/a56cdf64a28bcf13a233 to your computer and use it in GitHub Desktop.
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
function bind(self, fn) { | |
// arguments added beyond the two(self and fn) - store to be used by the bound function later (1) | |
var curryArgs = arguments.length > 2 ? sliceArgs(arguments, 2) : []; | |
if (isFunction(fn) && !(fn instanceof RegExp)) { | |
return curryArgs.length | |
? function() { | |
return arguments.length | |
? fn.apply(self, concat(curryArgs, arguments, 0)) | |
: fn.apply(self, curryArgs); | |
} | |
: function() { | |
return arguments.length | |
? fn.apply(self, arguments) | |
: fn.call(self); | |
}; | |
} else { | |
// in IE, native methods are not functions so they cannot be bound (note: they don't need to be) | |
return fn; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment