Skip to content

Instantly share code, notes, and snippets.

@ericelliott
Created May 20, 2016 04:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericelliott/4429bd470b8a6e85e43a88ff3869bbd0 to your computer and use it in GitHub Desktop.
Save ericelliott/4429bd470b8a6e85e43a88ff3869bbd0 to your computer and use it in GitHub Desktop.
Simple generator example
function* foo() {
yield 'a';
yield 'b';
yield 'c';
}
for (const val of foo()) {
console.log(val);
}
// a
// b
// c
const [...values] = foo();
console.log(values); // ['a','b','c']
@chiunhau
Copy link

Hello! Sorry for commenting here...I have a question:
Why there's no next() but you can still iterate it in the for loop?

@sibelius
Copy link

sibelius commented Jun 8, 2017

Because of yield and * generator syntax

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment