Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some thoughts on the use of bind method #4583

Open
Nirvana-Jie opened this issue Apr 5, 2022 · 0 comments
Open

Some thoughts on the use of bind method #4583

Nirvana-Jie opened this issue Apr 5, 2022 · 0 comments

Comments

@Nirvana-Jie
Copy link

Nirvana-Jie commented Apr 5, 2022

Is your feature request related to a problem? Please describe.

When I was looking at the code, I found a very magical thing. When we use the encapsulated bind method, we will find that when we extend the function, all the methods we mount are named wrap, which is unsemantic.

And every time we use the bind method, we will create an array,I think this will be a big waste of resources

Describe the solution you'd like

Describe alternatives you've considered

Additional context

Add any other context or screenshots about the feature request here.

module.exports = function bind(fn, thisArg) {
  return function wrap() {
    var args = new Array(arguments.length);
    for (var i = 0; i < args.length; i++) {
      args[i] = arguments[i];
    }
    return fn.apply(thisArg, args);
  };
};
function extend(a, b, thisArg) {
  forEach(b, function assignValue(val, key) {
    if (thisArg && typeof val === 'function') {
      a[key] = bind(val, thisArg);
    } else {
      a[key] = val;
    }
  });
  return a;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants