call 与 apply的区别
function calc(base,bonus1,bonus2){ console.log( this.ename+"的总工资是"+ (base+bonus1+bonus2)); } var lilei={ename:"Li Lei"}; var hmm={ename:"Han Meimei"}; //lilei临时强行借用函数calc calc.call(lilei,10000,1000,2000); //参数不是数组 calc.apply(hmm,[4000,3000,5000]); // 参数为数组 //lilei买一个新的属于自己的计算器: var lileiCalc=calc.bind(lilei,10000); // this base //创建一个和calc一模一样的新函数,并永久绑定this为lilei lileiCalc(1000,2000); //bonus1 bonus2 //lileiCalc.call(hmm,3000,5000);
运行结果: