Check the Underscore docs for omit
! You can see that it does not take an array as its second parameter, but rather takes multiple parameters. Valid invocations would be
_.omit({…}, "a")
_.omit({…}, "a", "b")
_.omit({…}, "a", "b", …, "z")
Also have a look at the code of _.omit
.
So why does your second invocation work at all? Because the one-element array (['a']
) that you're passing in gets stringified and yields the expected property name.
But how can you call omit
with variable arguments? Especially, _.keys(newNames)
does yield differently sized arrays. And this is just where apply
is required.
At least, that's what the author intended to do.
Yet, I stand corrected. If we actually look at the source code, we can see the line
var keys = concat.apply(ArrayProto, slice.call(arguments, 1));
So, by using concat
it allows the user to supply a variable amout of strings or arrays of strings. This means you're right, and using apply
is just overly complicated.