Skip to content

Instantly share code, notes, and snippets.

@englishextra
Forked from Daniel-Hug/function-bind.js
Last active May 1, 2017 22:11
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 englishextra/db0f22a60e59de86c19f174938c09529 to your computer and use it in GitHub Desktop.
Save englishextra/db0f22a60e59de86c19f174938c09529 to your computer and use it in GitHub Desktop.
Polyfill for Function.prototype.bind
/*!
* Polyfill for Function.prototype.bind
* @see {@link https://gist.github.com/Daniel-Hug/5682738}
* @see {@link https://gist.github.com/englishextra/db0f22a60e59de86c19f174938c09529}
*/
if (!Function.prototype.bind) {
Function.prototype.bind = (function () {}).bind || function (b) {
if (typeof this !== "function") {
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
}
function c() {}
var a = [].slice,
f = a.call(arguments, 1),
e = this,
d = function () {
return e.apply(this instanceof c ? this : b || window, f.concat(a.call(arguments)));
};
c.prototype = this.prototype;
d.prototype = new c();
return d;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment