var person = {
name: "taylor",
age: 25
};
function say(job){
console.log(this.name+":"+this.age+" "+job);
}
//call方法后的参数一为调用对象,参数二为携带的参数
say.call(person,"student"); // taylor:25 student
//apply方法后的参数一为调用对象,参数二为携带的参数,参数必须为数组对象
say.apply(person,["student"]); //taylor:25 student
//bind 绑定是在运行时绑定,且只能绑定一次
var sayPerson = say.bind(person,"student");
sayPerson(); // taylor:25 student
apply和call和bind区别
最新推荐文章于 2022-04-22 09:36:22 发布