Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

剩余参数和 arguments 对象的区别是什么? #82

Open
LuckyWinty opened this issue Dec 6, 2020 · 2 comments
Open

剩余参数和 arguments 对象的区别是什么? #82

LuckyWinty opened this issue Dec 6, 2020 · 2 comments
Labels

Comments

@LuckyWinty
Copy link
Owner

No description provided.

@LuckyWinty LuckyWinty added the js label Dec 6, 2020
@LuckyWinty
Copy link
Owner Author

  1. 剩余参数只包含那些没有对应形参的实参(可以是参数的 部分),而 arguments 对象包含了传给函数的所有实参(是参数的全部)
  2. arguments 对象不是一个真实的数组,而剩余参数是真实的 Array 实例 也就是说,能够在它上面直接使用所有的数组方法,比如 sort、map、forEach、pop
  3. arguments 对象还有一些附加的属性(如 callee 属性)
  4. 如果想在 arguments 对象上使用数组方法,首先要将它转换为真实的数组,比如使用 [].slice.call(arguments)

@SiHao24
Copy link

SiHao24 commented Dec 7, 2020

补充第四条

  1. Array.from(arguments)
  2. [... arguments]
  3. Array.protoType.slice.call(arguments)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants