Skip to content

Instantly share code, notes, and snippets.

@ramil-k
Created June 22, 2018 18:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ramil-k/91b1f785df6f60757b1d88d7d1eaa336 to your computer and use it in GitHub Desktop.
Save ramil-k/91b1f785df6f60757b1d88d7d1eaa336 to your computer and use it in GitHub Desktop.
iterators to generators
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