我研究以下代码进行记录
console.log.apply( console, arguments );
apply()
在这里的目的是什么?为什么不只是
console.log("message", arguments)
?谢谢。
最佳答案
apply()
函数调用另一个函数,该函数具有给定的this
值和作为数组提供的arguments
。
隐式func.apply(obj, args)
的原因是要确保在func()
中,this
引用了obj
。
我研究以下代码进行记录
console.log.apply( console, arguments );
apply()
在这里的目的是什么?console.log("message", arguments)
?最佳答案
apply()
函数调用另一个函数,该函数具有给定的this
值和作为数组提供的arguments
。
隐式func.apply(obj, args)
的原因是要确保在func()
中,this
引用了obj
。