将"Arguments to bind"改写为"bind()方法的参数"
示例代码:
const person = {
name: 'John',
age: 30
};
function introduce(city, country) {
console.log(`My name is ${this.name}, I am ${this.age} years old, and I am from ${city}, ${country}.`);
}
const boundIntroduce = introduce.bind(person);
boundIntroduce('New York', 'USA');
以上代码中,使用了bind()方法将introduce函数中的this绑定到person对象上。bind()方法接收的参数就是要绑定到this上的对象。在此示例中,person对象就是bind()方法的参数。