JavaScript中call、apply个人理解
一句话即通俗的说:call、apply 是为了改变this的状态而存在的
var lisi = {name:'李四',age:23};
var zs = {name:'张三',age:100}
function personInfo(name,age){
this.name = name;
this.age = age;
}
personInfo.prototype = {
showInfo:function(){
console.log('我是'+this.name+','+'今年'+this.age+'岁。');
}
}
var p = new personInfo('王五',23);
p.showInfo.apply(lisi);
p.showInfo.call(lisi);
p.showInfo.apply(zs);
p.showInfo.call(zs);
结果: