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

【再学前端】自己动手模拟实现 bind() 方法 #135

Open
Samgao0312 opened this issue Jul 3, 2022 · 0 comments
Open

【再学前端】自己动手模拟实现 bind() 方法 #135

Samgao0312 opened this issue Jul 3, 2022 · 0 comments

Comments

@Samgao0312
Copy link
Owner

描述: bind() 方法创建返回一个新的函数。新函数中的 this 指向 bind() 被调用时传入的第一个参数,而其余参数将作为新函数的参数,供调用时使用。
语法: function.bind(thisArg[, arg1[, arg2[, ...]]])

const Obj = {
  name: 'G-Dragon',
  age: 30,
  sayName() {
    return 'Hi, I am ' + this.name;
  }
}
console.log(Obj.sayName())  //Hi, I am G-Dragon
let func = Obj.sayName.bind({ name: '高龙' }, 1, 12);
console.log(func())  //Hi, I am 高龙

参考阅读

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