我发现以下功能很好:
while ((_next = itr.next()) && !_next.done) {
...
}
在没有任何_next
的先前声明的情况下,如果我声明了变量while ((let _next = itr.next()) ...
,traceur实际上会抛出一个意外的关键字错误。
这是ECMAScript 6吗?
while ((let _next = itr.next()) ...
这是ECMAScript 6吗?
没有。while
语句必须包含表达式,而不是变量声明。分组运算符中的变量声明无论如何都是无效的。自ES5以来,这种情况一直没有改变。
使用
var _next;
while ((_next = itr.next()) && !_next.done) {
…
}
或者只是
for (let … of itr) {
…
}