'function *' is not mandatory

Jason Orendorff jason.orendorff at gmail.com
Wed Sep 4 04:50:33 PDT 2013


On Tue, Sep 3, 2013 at 9:54 PM, François REMY
<francois.remy.dev at outlook.com> wrote:
>     - We don't want to introduce magic stuff where it isn't needed, but we want to keep most of the power of syntaxic sugar. Iterators are kinda achievable in pure ES5, only complex to write (state machine) and sometimes even more to read. However we should probably allow someone that want to implement is own "yield" logic to do so if he wants to, and not restrict the Iterator usage to the sole built-in "yield syntax" (this follows the Extensible Web principles).

It sounds like you are saying that generators are too high-level, and
it would be better to expose a lower-level primitive.

But what would that lower-level primitive be? What operations would it expose?

> When working under this set of assumptions, I came with the following idea:
> [...]
> Basically, using yield into a function create a state machine for the function and does run the function normally until the first encountered state switch (first yield statement here). In some sense, the function is almost normal, we could barely consider this kind of "yield" like a new kind of "return" that also return a pointer to a function that allows to continue the execution. You can totally write that in plain JS which will allow TypeScript-like compilers to generate for you the ES5-compatible code for your ES6 iterator, and use it on ES5-compatible browsers the exact same way you do on an ES6-browser.

How is any of this different from generators?

http://goo.gl/Flf2ru

-j


More information about the es-discuss mailing list