arguments 对象在 ES6 中应该是可迭代的吗?

Is the arguments object supposed to be an iterable in ES6?

在 ES6 中,当传递给 Set 构造函数时,我试图将 arguments 对象用作可迭代对象。它在 IE11 和 Chrome 47 中工作正常。它在 Firefox 43 中不起作用(抛出 TypeError: arguments is not iterable)。我查看了 ES6 规范,但无法真正找到 arguments 对象是否应该是可迭代对象的定义。

这是我尝试做的一个例子:

function destroyer(arr) {
  var removes = new Set(arguments);
  return arr.filter(function(item) {
    return !removes.has(item);
  });
}

// remove items 2, 3, 5 from the passed in array
var result = destroyer([3, 5, 1, 2, 2], 2, 3, 5);
log(result);

仅供参考,我知道此代码有多种解决方法,例如将参数对象复制到实际数组中或使用剩余参数。这个问题是关于 arguments 对象在 ES6 中是否应该是一个 iterable 可以在任何需要迭代的地方使用。

我想这是 FF 实现中的一个错误。

根据 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) 部分,

If argumentsObjectNeeded is true, then

a) If strict is true or if simpleParameterList is false, then

==> i) Let ao be CreateUnmappedArgumentsObject(argumentsList).

b) Else,

==> i) NOTE mapped argument object is only provided for non-strict functions that don’t have a rest parameter, any parameter default value initializers, or any destructured parameters .

==> ii) Let ao be CreateMappedArgumentsObject(func, formals, argumentsList, env).

两个CreateMappedArgumentsObject and CreateUnmappedArgumentsObject都有

Perform DefinePropertyOrThrow(obj, @@iterator, PropertyDescriptor {[[Value]]:%ArrayProto_values%, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true}).

表示@@iterator 属性实际上应该是在arguments对象上定义的