这是我正试图做的一个例子:
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],5); log(result);
FYI,我知道这个代码有各种各样的解决方案,比如将参数对象复制到一个真实的数组或者使用rest参数.这个问题是关于参数对象在ES6中是否应该是可迭代的,可以在任何地方使用迭代.
解决方法
根据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
和CreateUnmappedArgumentsObject
都有
Perform DefinePropertyOrThrow(obj,@@iterator,PropertyDescriptor {[[Value]]:%ArrayProto_values%,[[Writable]]: true,[[Enumerable]]: false,[[Configurable]]: true}).
原文地址:https://www.jb51.cc/js/153542.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。