-
-
Save ramil-k/91b1f785df6f60757b1d88d7d1eaa336 to your computer and use it in GitHub Desktop.
iterators to generators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const movies = { | |
action: ['dark', 'aveng'], | |
comedy: ['life', 'lights'], | |
[Symbol.iterator]*() { | |
for (let movies of Object.values(this)) { | |
// option 1: | |
for (let movie of movies) { | |
yield movie; | |
} | |
// option 2 (see https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Statements/function* for details): | |
// yield* movies; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment