admin管理员组文章数量:1384418
In ES6, I was trying to use the arguments
object as an iterable when passed to the Set
constructor. It works fine in IE11 and in Chrome 47. It does not work in Firefox 43 (throws a TypeError: arguments is not iterable
). I've looked through the ES6 spec and cannot really find a definition of whether the arguments
object should be an iterable or not.
Here's an example of what I was trying to do:
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);
FYI, I know there are various work-arounds for this code such as copying the arguments object into a real array or using rest arguments. This question is about whether the arguments
object is supposed to be an iterable
or not in ES6 that can be used anywhere iterables are expected.
In ES6, I was trying to use the arguments
object as an iterable when passed to the Set
constructor. It works fine in IE11 and in Chrome 47. It does not work in Firefox 43 (throws a TypeError: arguments is not iterable
). I've looked through the ES6 spec and cannot really find a definition of whether the arguments
object should be an iterable or not.
Here's an example of what I was trying to do:
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);
FYI, I know there are various work-arounds for this code such as copying the arguments object into a real array or using rest arguments. This question is about whether the arguments
object is supposed to be an iterable
or not in ES6 that can be used anywhere iterables are expected.
- 2 This is a known FF bug: The arguments object should support the ES6 @@iterator protocol – apsillers Commented Jan 5, 2016 at 15:16
- @apsillers - And it looks like the code has already been written to fix it (last month) and it is in the process of being reviewed and tested. – jfriend00 Commented Jan 5, 2016 at 15:40
1 Answer
Reset to default 9I suppose it is a bug in FF's implementation.
As per 9.2.12 FunctionDeclarationInstantiation(func, argumentsList) section,
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).
Both CreateMappedArgumentsObject
and CreateUnmappedArgumentsObject
have
Perform DefinePropertyOrThrow(obj, @@iterator, PropertyDescriptor {[[Value]]:%ArrayProto_values%, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true}).
It means that @@iterator
property should have been actually defined on the arguments
object.
本文标签: javascriptIs the arguments object supposed to be an iterable in ES6Stack Overflow
版权声明:本文标题:javascript - Is the arguments object supposed to be an iterable in ES6? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744530790a2611022.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论