Skip to content

Instantly share code, notes, and snippets.

@yellownoggin
Last active August 29, 2015 14:15
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 yellownoggin/a56cdf64a28bcf13a233 to your computer and use it in GitHub Desktop.
Save yellownoggin/a56cdf64a28bcf13a233 to your computer and use it in GitHub Desktop.
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