Iterators and generators - MDC Doc Center
While custom iterators are a useful tool, their creation requires careful programming due to the need to explicitly maintain their internal state. Generators provide a powerful alternative: they allow you to define an iterative algorithm by writing a single function which can maintain its own state.
A generator is a special type of function that works as a factory for iterators. A function becomes a generator if it contains one or more
yieldexpressions.
Javascript 的作法:
我們提供 Iterator 物件,也讓你用 prototype 來定義 custom iterator,
如果你不想自己寫,我們也提供 iterator 的 factory,generator,
此時的作法就要用關鍵字 yield。