SUMMARY
Iteration is a pattern that is encountered in essentially every programming language. The ECMAScript 6 specification formally embraces the concept of iteration by introducing two formal concepts in the language, iterators and generators.
An iterator is an interface that can be implemented by any object and allows for successive visitation of values that it produces. Anything that implements the Iterable
interface features a Symbol.iterator
property, which references the default iterator. The default iterator behaves as an iterator factory: a function which, when invoked, produces an object that implements the Iterator
interface.
Successive values are coerced from an iterator via its next()
method, which returns an IteratorObject
. This object contains a done
property, a Boolean indicating if there are more values available, and a value
property, which contains the present value provided from the iterator. This interface can be manually consumed by invoking next()
repeatedly, or...