Why do console.log() polyfills not use Function.apply()?

為{幸葍}努か 提交于 2019-12-05 06:22:30

I would personally suggest that you only use .apply() when you have to: .apply() is the only way to pass an array as the arguments of a function. If you don't need to pass an array, then just use console.log(). It is less verbose and it is a direct invocation.

Please note that apply takes an array of arguments!

So calling console.log(args) have to be console.log.apply(console, [args]), not console.log.apply(console, args) to behave equal - in your example each item in array becomes his very own argument in apply.

On the other hand you may also call console.log("foo", "bar", $("body"))

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!