Generator functions have to be defined like this
function * simpleGenerator() { # Note the `*` after `function` keyword
yield "first";
yield "second";
yield "third";
};
var g = simpleGenerator();
console.log(g.next());
# { value: 'first', done: false }
Quoting from the ECMA 6's Harmony page for Generator functions,
The function syntax is extended to add an optional * token:
FunctionDeclaration:
"function" "*"? Identifier "(" FormalParameterList? ")" "{" FunctionBody "}" FunctionExpression:
"function" "*"? Identifier? "(" FormalParameterList? ")" "{" FunctionBody "}"
A function with a * token is known as a generator function. The following two unary operators are only allowed in the immediate body of a generator function (i.e., in the body but not
nested inside another function):
AssignmentExpression:
...
YieldExpression
YieldExpression:
"yield" ("*"? AssignmentExpression)?
An early error is raised if a yield or yield* expression occurs in a non-generator function.YieldExpression: