Skip to content

Instantly share code, notes, and snippets.

@maruf89
Created November 6, 2013 22:42
Show Gist options
  • Save maruf89/7345543 to your computer and use it in GitHub Desktop.
Save maruf89/7345543 to your computer and use it in GitHub Desktop.
Experimenting with a polyfill for bind
Function.prototype.bind = function(obj) {
if (Function.prototype.bind) { return Function.prototype.bind.apply(this, arguments) }
var that = this,
slice = function(a, b) { return a.length - (b || 0) ? Array.prototype.slice.call(a, b || 0) : [] },
concat = function(a, b) { return a.length ? b.length ? a.concat(b) : a : b; },
args = slice(arguments, 1);
return function() {
that.apply(obj, concat(args, slice(arguments)));
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment