Skip to content

Instantly share code, notes, and snippets.

@flying-sheep
Created May 22, 2013 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flying-sheep/5627847 to your computer and use it in GitHub Desktop.
Save flying-sheep/5627847 to your computer and use it in GitHub Desktop.
Firefox Generator/Iterator glossary

Glossary

Iterator
Object with .next(), .send(obj) and .close() methods.

It is iterable via for...of and for...in loops. Both ways act the same, i.e. call .next() repeatedly until it throws a StopIteration.

Generator expression
Iterator created via e.g. (x*2 for (x of array)).

  • Can be assigned to a variable (⇒ Generator comprehension),
  • used in function call braces to create arguments (e.g. MyListClass(x for (x of myArray))),
  • or used with brackets instead of braces, which makes it an Array comprehension (e.g. var keys = [x for (x in myObject)])

Generator function
Iterator factory created via e.g. function g() { yield 1; yield 2 }.

A call to g() will return a new Iterator.

ECMA 6 Iterable
An object with an .iterator(…) method that returns a generator function. It is iterable via for...of.

JavaScript 1.7 Iterable
An object with an .__iterator__(…) method that returns a generator function. It is iterable via for...in.

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