为什么console.log()polyfill不使用Function.apply()?

Dav*_*Eyk 7 javascript debugging polyfills

我一直在寻找一些流行的console.log()包装纸/填料:

我注意到他们都接受多个arguments,但他们都做这样的事情:

console.log(arguments);
Run Code Online (Sandbox Code Playgroud)

这导致像这样的输出(在Chrome中):

<code>console.log()</code>也接受多个参数,这样就可以产生(恕我直言)卓越的输出:</p>

<pre><code>console.log.apply(console, arguments)
</code></pre><a target=Run Code Online (Sandbox Code Playgroud)

这导致像这样的输出(在Chrome中):

<code>console.log.apply()</code>多个参数?或者这仅仅是品味或节省字节的问题?</p></p>
    </div>
  </div>

<div class=

小智 1

我个人建议您仅.apply()在必要时使用:.apply()是传递数组作为函数参数的唯一方法。如果不需要传递数组,则只需使用console.log(). 它不太冗长,并且是直接调用。