In the previous episode, I stumbled my way through ES6 Generator Iterators (using generators to iterate through items). About halfway through it, though, I got really confused. I wanted to try and do something fun, something more advanced… and I failed miserably. I got confused by generators and I couldn't figure out what was going on.
But I promised I would be back with more information in hand, and I am!
In this episode, then, I will show you how generators actually work – including the magic behind the scenes of iterators. You'll see how generators can “yield” data out of a function, and receive next back in to the same function. You'll see when the “yield” keyword actually fires after calling a generator function, and when data flows and and back in. You'll also see how generator functions don't actually execute immediately when invoked!
… wait, what?! Generator functions don't execute immediately, when invoked?!
That's right! Join me in this episode as I wrap my head around the way generators actually work, and explore how and when they execute using the “yield” statement and “iterator.next()” calls.