javascript - Wsy 这个箭头函数不适用于“arguments.length”吗?
问题描述
我想知道为什么以下名为“countArg2”的箭头函数不起作用。有没有人可以解释什么是错的?
这有效
function countArg1() {
return arguments.length;
}
countArg1(1, 2, 3); //3
这个不行。。
const countArg2 = () => arguments.length;
countArg2(1, 2, 3);
// VM6745:1 Uncaught ReferenceError: arguments is not defined
先感谢您。
解决方案
您必须像这样解析箭头函数的参数
const countArg2 = (...arguments) => arguments.length;
console.log(countArg2(1, 2, 3));
// VM6745:1 Uncaught ReferenceError: arguments is not defined
// at mArgs (<anonymous>:1:29)
// at <anonymous>:2:1
推荐阅读
- common-lisp - 右对齐文本 Lisp
- html - 为什么我的谷歌高级搜索出现这个错误?
- swift - 如何在自制的 Mac OS 应用程序中打开外部文件
- vue.js - 如何使用 Vuelidate 验证
- swift - Swift 的 SQLite3 查询中使用什么字符串类型?
- flutter - 如何从下拉菜单中正确返回选定的值(字符串)?
- java - 使用 mvn 版本排除属性:使用 excludesList 更新属性
- python - 封装的概念在 Python 中是如何工作的?
- python - 使用 Python API Client for Grakn 加载数据时出现问题
- arrays - 将 int 分配给结构数组但打印为 0(不同)