在JS的函数中,有一个arguments 的特殊类数组对象,arguments 按参数索引包含所有的参数
但是箭头函数是没有 arguments ,如果在箭头函数中访问 arguments,访问到的 arguments
并不属于箭头函数,而是属于箭头函数外部的“普通”函数
function showArguments() {
console.dir(arguments) // 显示一个对象的所有属性和方法
// arguments 可以被遍历,但不支持所有数组方法
for(let arg of arguments) {
console.log(arg) // John 18
}
}
showArguments('John', 18)
let arr = ['John', 18] // 直接定义一个arr数组
console.dir(arr)