In many situations, using arguments
to pass the function args would lead to bugs as we totally unaware the actual args. When to use these such notations and when not to?
In many situations, using arguments
to pass the function args would lead to bugs as we totally unaware the actual args. When to use these such notations and when not to?
For further actions, you may consider blocking this person and/or reporting abuse
First note, try not to use
arguments
as it was reserved in the past and not allowed in strict mode anymore.Also are you referring to
function_call(...args);
orfunction call_me(...args) {}
?function_call(...args)
That is a type of array destructuring and can be used to pass the elements of an array to a function.
is equivalent to
yeah, but in a component model, when handling functions, it becomes black box
now, I completely unaware of the argument list!
the value of
arguments
here is the value of the arguments passed topassToAnotherFunc
. See the deprecated arguments objectWait, the
arguments
isn't deprecated, it's onlyarguments.caller
property that's non-standard and deprecated.Combining Meghan's two earlier responses, a better way would be:
But I feel it's unlikely you'd need to write this kind of code. Could you give a real-world example?
@antjanus it's not deprecated per-se but it is disabled in strict and module mode.
@shalvah +1 because instead of calling
passToAnotherFunc
to callhandleItSomewhere
, why not just callhandleItSomewhere
?I had no idea it was disabled in strict/module mode!
Is useful, for example, if doesn't matter how many parameters receive the function:
Generally speaking you should only use it if you were writing some library i guess. Most of the time i just use it for debugging. But you're right that it would probably be buggy in most cases.