I've been looking at some of the popular console.log()
wrappers/polyfills:
I notice that all of them accept multiple arguments
, but they all do something like this:
console.log(arguments);
Which results in output like this (in Chrome):
Whereas, at least in a modern browser like Chrome or Firefox, console.log()
also accepts multiple arguments, so that this would produce (IMHO) superior output:
console.log.apply(console, arguments)
Which results in output like this (in Chrome):
Is there any particular reason why I should avoid using console.log.apply()
with multiple arguments? Or this this just a matter of taste or saving bytes?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With