Created
March 2, 2021 19:20
-
-
Save AMashoshyna/cd2e75960afc983cb572914f5e7625cb to your computer and use it in GitHub Desktop.
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 sum(...numbers) { | |
return numbers.reduce((x, y) => x + y, this.initialValue) | |
} | |
Function.prototype.myBind = function(context, ...boundArgs) { | |
return (...ownArgs) => { | |
return this.apply(context, [...boundArgs, ...ownArgs]) | |
} | |
} | |
const context = { | |
initialValue: 5 | |
} | |
console.assert(sum.bind(context, 1)(2, 3) === sum.myBind(context, 1)(2, 3)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment