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

【挑战系列10】实现bind方法 #12

Open
Chocolate1999 opened this issue Sep 1, 2020 · 0 comments
Open

【挑战系列10】实现bind方法 #12

Chocolate1999 opened this issue Sep 1, 2020 · 0 comments

Comments

@Chocolate1999
Copy link
Owner

/* 实现bind方法 */
function bar(name, age,city) {
  console.log(name)
  console.log(age)
  console.log(this.value);
  console.log(city)
}
var foo = {
  value: 1
};

Function.prototype.myBind  = function(content = window){
  let that = this
  let args = [...arguments[1]]
  return function fn(){
    return that.apply(content,args.concat([...arguments]))
  }
}
bar.myBind(foo, ['kevin', 18])('北京')
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

1 participant