Last active
April 20, 2023 05:22
-
-
Save abhinavnigam2207/fff31e8ba7d7b0a4c40aec8e13192717 to your computer and use it in GitHub Desktop.
Bind polyfill
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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