JavaScript arguments Object

JavaScript arguments Object

7月 24, 2021 · 1 分钟阅读时长 · 128 字 · -阅读 -评论

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.

Alan H
Authors
开发者,数码产品爱好者,喜欢折腾,喜欢分享,喜欢开源