Created
July 24, 2019 13:41
-
-
Save nathan-lapinski/174494f8284a107654611cd2497beed5 to your computer and use it in GitHub Desktop.
a quick bind
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 myBind(fn, context, ...args) { | |
return function(...moreArgs) { | |
return fn.call(context, ...(args.concat(moreArgs))); | |
} | |
} | |
// test | |
function add(a,b,c) { | |
return a + b + c; | |
} | |
console.log(myBind(add, null, 1,2)(3)) // 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment