arguments 是一个类数组,如何遍历它?
参考答案
for (let i = 0; i < arguments.length; i++)Array.from(arguments).forEach(...)[...arguments]/Array.prototype.slice.call(arguments)for...of(arguments 是可迭代对象,现代浏览器支持)Array.prototype.forEach.call(arguments, fn)
注意:箭头函数没有 arguments,需用 rest 参数 (...args);严格模式下 arguments 与形参不联动。