Skip to content

Instantly share code, notes, and snippets.

@AMashoshyna
Created March 2, 2021 19:20
Show Gist options
  • Save AMashoshyna/cd2e75960afc983cb572914f5e7625cb to your computer and use it in GitHub Desktop.
Save AMashoshyna/cd2e75960afc983cb572914f5e7625cb to your computer and use it in GitHub Desktop.
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