A generator is a function that can be started and stopped through the use of an iterator. The yield keyword indicates where the function should pause and what value should be returned at that pause. A done property is returned along with the yielded value to indicate if the function has finished running.
(upbeat music)…- We're gonna come back to this example in just a moment…and rewrite it, but I want to take a quick little detour…and talk to you about the last feature…that I'm gonna introduce to you today…which is called a generator.…Now I do not have time to fully explain all that happens…with generators, so I'm gonna give you kind of…a shortcut explanation and strongly encourage you…to go do some more reading about them.…I've got several blog posts out there,…they're covered in two of my books.…I strongly recommend you read a lot more about generators,…so I'm not gonna fully explain all the whys and hows…of it, 'cause that would take another several hours.…
I'm just gonna quickly introduce them to you…so we can see how they can be useful.…Generators look like this.…We put the star there and then we give it some kind of name.…It doesn't have to be a name, it could be an anonymous but…generators need that star there.…Now what's interesting about a generator,…if I just have something silly like this,…what's interesting about a generator is that when I call it,…
This course was created by Frontend Masters. It was originally released on 01/10/2017. We're pleased to host this training in our library.
- The arrow function
- Arrow function variations
- Closures and explicit blocks
- Default values
- Using the gather and spread operators
- Dumping variables
- Concise properties and methods
- Symbols, iterators, and generators
- Optimizing codes for the reader
Skill Level Intermediate
1. Arrow Functions
2. Block Scope
3. Default Values and the Gather/Spread Operators
5. Template Strings
6. Symbols, Iterators, and Generators
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.