DEV Community

Discussion on: Creating your own bind() (Polyfill of bind)

Collapse
 
prashan81992916 profile image
prashanth

This is a pretty cool post.

I would like to make a small alteration in your code.
We can eliminate the need for storing 'this' in the parent scope and using it at the time by invocation by making use of arrow function.

Function.prototype.myBind = function (obj, ...args) {
  return (...newArgs) => this.apply(obj, [...args, ...newArgs]);
};
Enter fullscreen mode Exit fullscreen mode

Hope this helps!!