Javascript Generators – THEY CHANGE EVERYTHING – ES6 Generators Harmony Generators




Javascript Generators are AWESOME. At first glance, they seem overly simple and not very useful, but with a little bit of library love, they turn your async javascript from awful to joyful.

View the code here: https://gist.github.com/learncodeacademy/bf04432597334190bef4

If you don’t know promises, watch this video: http://www.youtube.com/watch?v=obaSQBBWZLk&list=UUVTlvUkGslCV_h-nSAId8Sw

Basically, ES6 generators give you the ability to write async code as if it were synchronous code. It literally looks like you’re not even writing async code! Harmony generators are definitely, without a doubt, the most powerful upgrade that javascript is receiving with ES6 harmony.

Original source


40 responses to “Javascript Generators – THEY CHANGE EVERYTHING – ES6 Generators Harmony Generators”

  1. Can you guys clarify something for me? This example tells us that we can not call next() on a closed generator. I tried this in both Node and the browser and if I call next() a bunch of more times it just returns "value: undefined, done: true" over and over again. Has this changed since august 2014 when this video was made or am I overlooking something silly?

  2. wait what? yield only shots promise object when gen.next() is called, it doesn't wait for promise to resolve, that's single responsibility principle violation, or does it? I'm confused. Also isn't it just replica of Promise.all(), Promise.any() functionality? Video is delivered like it is completely new thing, but it's just a standardizing process of old stuff. Could someone explain?

  3. man, I like the last statement you made! and love seeing how I enjoy the rest of my JS life. In the past year, I have hands-on exp on JS and really like the idea of being a JS ninja, JS junkie. I see programming and coding in JS is not only fun but sharp, concise, efficient, way better syntactic (syntax + tactics) than tight-types. rigirous syntaxes of C# and Java.

    Because JS is loose-type, there comes easy ways to define objects, object classes and wire up things. There comes Prototypical programming patterns.

    The only downside of JS (weakness too as compared to years of C++,C#, Java drive them into standardized languages) is that JS from ECMA Script wasn't much developed in the past and the language undergoes exploration and development. Adjustment and changes come and create inconsistency, unconventional and unstandardized ecosystem for JS generations of developers. ECMA and Browser ( the compiler. IIRC: big name is Chrome) are still hesitant to have full exchange, collaboration and agreement on how things go for future web. I hope Google pushes it to have strong tie to future with ES forks.

  4. Great video! I was going through generator/promises tutorials and had no idea why the hell I was learning it for but it all clicked after watching this and the last video on promises. Thanks!

  5. holy shit! the possibilities of this functionality! i watched this a couple of months ago and it didnt make any sense but now that i know a little bit about functions i think this like what you said, "a game changer!"

  6. Js took many years to have a simple way of writing synchronous code in it's universal implementation, yet no thaaat simple…
    Still, I can't hide my enthusiasm with these new features that long existed everywhere

Leave a Reply