Lesson 18. Generator functions
After reading lesson 18, you will
- Know how to define generator functions
- Know how to yield values from generator functions
- Understand the generator function lifecycle
Generator functions are one of the harder things to comprehend among all the recent additions to JavaScript. They introduce a new form of code execution and processing that most JavaScript developers haven’t seen before. Generators aren’t new concepts, though—they’re already part of Python, C#, and other languages. This lesson is only meant to be a gentle introduction to the topic.
You’ll see how good generators are at creating lists, but that isn’t all generators are good for. That would be like saying objects are only useful for storing key/value ...
Get Get Programming with JavaScript Next now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.