Apa*_*ear 5 javascript generator node.js
我正在运行NodeJS控制台:
$ node --version
v0.12.0
Run Code Online (Sandbox Code Playgroud)
我正在尝试实现像这样的Generator功能
function* colorGen() {
var colors = ["red", "green", "blue", "white"]
var i = 0;
yield colors[i];
i += 1;
if (i > 3) {i = 0;}
}
Run Code Online (Sandbox Code Playgroud)
但是当我运行第一行时,我收到语法错误:
$ node
> function* colorGen() {
SyntaxError: Unexpected token *
at Object.exports.createScript (vm.js:44:10)
at REPLServer.defaultEval (repl.js:117:23)
at bound (domain.js:254:14)
at REPLServer.runBound [as eval] (domain.js:267:12)
at REPLServer.<anonymous> (repl.js:279:12)
at REPLServer.emit (events.js:107:17)
at REPLServer.Interface._onLine (readline.js:214:10)
at REPLServer.Interface._line (readline.js:553:8)
at REPLServer.Interface._ttyWrite (readline.js:830:14)
at ReadStream.onkeypress (readline.js:109:10)
>
Run Code Online (Sandbox Code Playgroud)
为什么会这样?
| 归档时间: |
|
| 查看次数: |
4818 次 |
| 最近记录: |