Can I use ES6's arrow function syntax with generators? (arrow notation)

Ashley Coolman picture Ashley Coolman · Dec 26, 2014 · Viewed 69.7k times · Source

ie how do I express this:

function *(next) {}

with arrow syntax. I've tried all the combinations I could think of, and I can't find any documentation on it.

(currently using node v0.11.14)

Answer

user663031 picture user663031 · Dec 26, 2014

Can I use ES6's arrow function syntax with generators?

You can't. Sorry.

According to MDN

The function* statement (function keyword followed by an asterisk) defines a generator function.

From a spec document (my emphasis):

The function syntax is extended to add an optional * token:

FunctionDeclaration: "function" "*"? Identifier "(" FormalParameterList? ")" 
  "{" FunctionBody "}"