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

rest 参数和arguments的区别 #10

Open
lovelmh13 opened this issue Feb 6, 2020 · 0 comments
Open

rest 参数和arguments的区别 #10

lovelmh13 opened this issue Feb 6, 2020 · 0 comments

Comments

@lovelmh13
Copy link
Owner

restarguments都可以获取多余参数。

  • arguments是获取全部传进来的参数
  • rest参数(...rest) 是获取声明的参数之外的参数
  • arguments 是类数组,只有length和索引元素,...rest获取的是货真价实的数组

arguments对象

  • arguments有多种属性,具体可以查MDN

rest参数

  • rest参数后面不能再写参数:
function   foo (a, ...b, c) {}  // ×错的
  • 函数的length属性,不包括rest参数

参考

阮一峰ES6

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

No branches or pull requests

1 participant