3 ms·
Here's a jsperf that tests just the arguments copy via slice, while loop, or for loop: http://jsperf.com/args-copy http://jsperf.com/args-copy In the browsers
by noonat 15y ago
Here's a jsperf that tests just the arguments copy via slice, while loop, or for loop: http://jsperf.com/args-copy http://jsperf.com/args-copy
In the browsers I tested in, it does indeed seem to be significantly faster to copy the array via a normal loop (in Chrome, Firefox, and WebKit mobile, at least). That said, don't start optimizing everything into for loops unless you've identified the code as a bottleneck. It's not worth the additional complexity for a function that's rarely called.