Skip to content

Instantly share code, notes, and snippets.

@HollyBang
Forked from ramil-k/i.js
Created June 29, 2018 16:01
Show Gist options
  • Select an option

  • Save HollyBang/f8f6d21e8b557951ca7fd4d4c7e17a40 to your computer and use it in GitHub Desktop.

Select an option

Save HollyBang/f8f6d21e8b557951ca7fd4d4c7e17a40 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