Arguments object enables you to treat function arguments with respect.. and the developers with compassion.
How do you pass arguments to a function?
In its most primitive form:
|
|
This is perfectly ok in an ideal world where Buddha walks the earth.
In the real world populated by Agent Smith and his compadres, one has to be more defensive with function arguments. One of the ways of doing that is by using arguments
.
|
|
Where should you use arguments?
- when input arguments can be one or more, but are homogenous (e.g. get me sum of all numbers supplied as arguments)
- when currying functions in Javascript
The alternative, and probably a more common pattern, is to use the rest operator or assignment destructuring against a single object passed as argument. This can be considered the next gen function and should replace the older arguments
object.
|
|
My preferred approach..
|
|