Implement `myBind(fn, context, ...args)` that behaves like Function.prototype.bind.
Problem Statement
Implement `myBind(fn, context, ...args)` that behaves like Function.prototype.bind.
Complexity
Time Complexity: -
Space Complexity: -
Hints
š” Hint 1:
bind() returns a new function with this set to context.
š” Hint 2:
Pre-fill some arguments and allow more to be passed when called.
š” Hint 3:
return (...laterArgs) => fn.apply(context, [...args, ...laterArgs]);
ā
Solution:
```javascript
function myBind(fn, context, ...args) {
return function(...laterArgs) {
return fn.apply(context, [...args, ...laterArgs]);
};
}
```