JavaScript arguments Object

This article provides an introduction to JavaScript arguments object, including its limitations, comparison with rest parameters, and migration strategies for modern JavaScript development.

Jul 24, 2021 · 1 min read · 128 Words · -Views -Comments · Programming
JavaScript 🇨🇳 阅读中文版
Read with AI

Choose an AI assistant

ChatGPT Open in a new tab with the article link and prompt
Claude Copy the prompt, then open Claude

Open Claude
Trouble reading the article?

If the prompt is missing, copy the full prompt below into your AI assistant. If the AI cannot read the article, paste the visible passage you want to discuss and add your question.

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.

Authors
Developer, digital product enthusiast, tinkerer, sharer, open source lover