Write Your Own Bind
Write the code, see it run, pass the checks.
The problem
- medium
- Code
Write myBind(fn, thisArg, ...preset) without using Function.prototype.bind (call and apply are fine). It returns a function that calls fn with this set to thisArg, and with the preset arguments followed by the arguments it was called with, and returns fn's result. The this the returned function is called with is ignored: it always uses thisArg.
Your code must pass
- Calls fn with this set to thisArg
- Puts the preset arguments before the call's own
- Ignores the this it's called with
- Works without Function.prototype.bind