Any object can have an iterator. Kyle demonstrates how to create a custom iterator on a basic object. He defines a Symbol.iterator property and initializes the iterator object with a next() method.
(electronic music)…- Alright, our final topic for us to pay attention to…is how do we make our own iterators.…What if I have a value, an object or something that…I've created, and I'd like for it to be consumable…through any of those various iterable consumptions…that we just talked about,…like dot-dot-dots or for-of loops or whatever?…It's a standard interface…but how do I make myself an iterator?…Well, there's the manual, crappy way…which I'm gonna show you first.…
And then there's a much nicer way,…using what we called generators.…So let's look at the old, crappy way first.…Let's say I wanted to make an object like this…and, I don't know, let's say that it had a limit on it of 13…and what I wanted to do is make...…Let's do this.…Let's just say it had those properties on it.…
What I wanted to do is I wanted to make it so…the object was iterable in that what it would do is…go through a list of values like this.…I'm gonna do this.…Two, four, six, eight, 10, 12.…I think I have enough now.…
Okay, so let's say that it has a values array.…
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.