3 ms·
You also can't implement generators using an array. There's a reason why generators were added to ES6 -- they aren't just syntactic sugar.
by pdubroy 12y ago
You also can't implement generators using an array. There's a reason why generators were added to ES6 -- they aren't just syntactic sugar.
- jkrems 12y agoIf they aren't just syntactic sugar - how to you think regenerator works? Show me a generator and I show you perfectly fine, synchronous (though verbose) ES5 code doing the exact same thing.
- pdubroy 12y agoWell, "syntactic sugar" usually refers to things that can be translated in a syntactically local, structure-preserving way. I'm aware that generators can be compiled down to an ES5 representation, but it requires non-trivial analysis. Take a look at the example on their home page: https://facebook.github.io/regenerator/ https://facebook.github.io/regenerator/. Do you also consider functions to be syntactic sugar? Because you can also implement them in terms of a switch statement.