ES6 - 使用箭头语法调用匿名生成器

ES6 - call anonymous generator with the arrow syntax

如何调用生成器:

const scenarioProvider = (function*() {
    ....
}).bind(this)();

通过箭头函数语法。我的意思是用新的 'lexical this' 替换 'bind(this)'。

这目前不可能,也不太可能包含在未来的 ecmascript 版本中。

Just to let everyone know (meeting notes, coming soon, will make this clear), we agreed not to do generator arrows. Too much trouble of the kind identified here...

来源:Brendan Eich @esdiscuss

根据定义,箭头函数是词法范围的。你不能use a generator with an arrow function

但是请注意,您不能绑定箭头函数。

MDN 状态:

An arrow function expression (also known as fat arrow function) has a shorter syntax compared to function expressions and lexically binds the this value (does not bind its own this, arguments, super, or new.target). Arrow functions are always anonymous.