【发布时间】:2014-12-13 08:51:32
【问题描述】:
当我使用 --harmony 选项启动节点 v0.11.14 REPL 并尝试 for-of 循环时,我得到:
> for (var i of [3, 4, 5]) console.log(i);
TypeError: undefined is not a function
套装也是如此。但它适用于生成器:
> function* Counter() { var n=3; while (n < 7) { yield n++; } }
> var c = new Counter();
> for (var i of c) console.log(i);
3
4
5
6
虽然ecmascript wiki page 的第一个例子是:
for (word of ["one", "two", "three"]) {
alert(word);
}
MDN page 和 Traceur docs 包含相同的示例。我没能用谷歌搜索“for-of in nodejs”。它真的应该在 Node 中工作还是我错过了什么?
【问题讨论】:
标签: javascript node.js ecmascript-6 ecmascript-harmony