Skip to content

Instantly share code, notes, and snippets.

@mertenvg
Last active April 26, 2024 04:52
Show Gist options
  • Save mertenvg/7097491 to your computer and use it in GitHub Desktop.
Save mertenvg/7097491 to your computer and use it in GitHub Desktop.
Function bind(obj[, arg1[, arg2[, ...]]]) polyfill
if (typeof Function.prototype.bind === 'undefined') {
/**
* Function bind(obj[, arg1[, arg2[, ...]]]) polyfill
*
* @param obj
*
* @returns {Function}
*/
Function.prototype.bind = function (obj) {
var fn = this,
args = [].slice.call(arguments, 1) || [];
if (typeof fn !== "function") {
throw new TypeError(fn.toString() + " is not a function. Unable to bind.");
}
return function () {
fn.apply(obj, args.concat([].slice.call(arguments)));
};
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment