JavaScript arguments Object
·
1 min read
·
128
Words
·
-Views
-Comments
Due to historical reasons, some functions in project code still use arguments, and the company’s lint rules only give warnings for arguments usage, so some haven’t been modified.
So is arguments still necessary? Here’s a summary.
arguments vs rest parameters
- arguments is array-like but not a real array, so it lacks methods like map, filter, etc., while rest parameters are actual arrays
- Iterator methods for arguments are not supported in IE
- arguments is from ES3 specification, while rest parameters are from ES6
- rest parameters can be used to get all function parameters and can completely replace arguments
In conclusion, we can definitely use rest parameters to handle parameter retrieval
prefer-rest-params
For legacy code, this rule can be used for detection and fixing. It’s better to resolve errors individually.