不同之处在于
apply,您
arguments可以使用数组作为函数来调用函数。
call需要明确列出参数。有用的助记是 “ 甲用于
一个rray和ç为 ÇOMMA”。
有关apply和call的信息,请参见MDN的文档。
伪语法:
theFunction.apply(valueForThis, arrayOfArgs)
theFunction.call(valueForThis, arg1, arg2, ...)
从ES6开始,
spread数组
call也可以与该函数一起使用,您可以在此处查看兼容性。
样例代码:
function theFunction(name, profession) { console.log("My name is " + name + " and I am a " + profession +".");}theFunction("John", "fireman");theFunction.apply(undefined, ["Susan", "school teacher"]);theFunction.call(undefined, "Claude", "mathematician");theFunction.call(undefined, ...["Matthew", "physicist"]); // used with the spread operator


