apply,call,bind,及一般调用
一般调用:
function test(){ console.log("test"); } test();
调用带this的函数:
function test(arg1,arg2,arg3){ console.log("test "+this.name+arg1+arg2+arg3); } //test();//this.name为空,输出结果有误 let obj={ name:"Jack" } //下面两个语句等效,apply和call使test中的this指向obj,只是传参方式略有不同 test.apply(obj,["AA","BB","CC"]); test.call(obj,"AA","BB","CC"); //绑定语句,生成新函数 let newFunc=test.bind(obj,"AA","BB","CC"); newFunc();