Considering that args
is array-like iterable, it is
function.call(context, ...args);
// vs
function.apply(context, args);
And apply
is shorter.
apply
is native and thus faster than call
with spread arguments. The difference can vary between browser versions and be negligible (recent Chrome/V8) or drastic (Firefox, older Chrome/V8). Depending on the case, this concern may be considered preliminary optimization.
The results can differ between browser versions, depending on the existence of optimizations for spread syntax and arguments
. Previously array-like arguments
could kill optimization in apply
, notably in V8. This is no longer a problem in modern engines that support spread syntax.
Practical difference appears if arguments are array-like but not iterable. For instance, arguments
became iterable not so long ago, ...arguments
will fail in older browser versions even if they support spread syntax. So apply
is preferable here, because call
would need a safety device:
function.call(context, ...Array.from(arguments));
// vs
function.apply(context, arguments);
On the other hand, there is practical difference if arguments are iterable but not array-like, too. Since apply
accepts array-likes, call
will be preferable and likely faster:
function.call(context, ...set);
// vs
function.apply(context, [...set]);