Kyle revisits the custom iterator code to show how it could be written using a generator instead of a custom iterator. This is possible because generators produce an iterator.
- Let's try to make this a little more concrete.…Let's come back to our example here…and let's think about…how would we make this obj object iterable.…Well, I do need a Symbol.iterator here, right?…But pretty much almost all of this stuff goes away.…That's a good start, (laughs) right?…Now, we want our Symbol.iterator to produce an iterator.…What data type did we just find out…automatically produces iterators?…Generators, so let's do a concise computed generator method.…
Now, this thing needs to simply spit out values.…Here's what it's gonna do,…for,…var,…i=this.start,…i<=this.end,…i++,…yield this.values of i.…
Done.…Think about what that's doing.…It's producing an iterator…that is going to start at our this.start location,…loop over its values array,…and just yield out whatever it finds in that values array.…
I'm pretty sure if I was hard-pressed,…I would have to tell you, generator is either my favorite…or my second favorite feature.…It's a tie between generators and destructuring…in terms of my favorite most powerful features.…
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.