Skip to content

Instantly share code, notes, and snippets.

@abhinavnigam2207
Last active April 20, 2023 05:22
Show Gist options
  • Save abhinavnigam2207/fff31e8ba7d7b0a4c40aec8e13192717 to your computer and use it in GitHub Desktop.
Save abhinavnigam2207/fff31e8ba7d7b0a4c40aec8e13192717 to your computer and use it in GitHub Desktop.
Bind polyfill
Function.prototype.myBind = function(...boundArgs) {
let func = this;
let context = boundArgs.shift();
if (typeof this !== "function") {
throw new Error(this + "cannot be bound as it's not callable");
}
return function(...targetArgs) {
func.apply(context, args.concat(targetArgs));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment