JSadvancedes2015
Generators and iterators
Sequences, paused on demand.
A generator is a function you can pause and resume. It hands back values one at a time, only computing the next when you ask — which makes lazy and even infinite sequences trivial.
A lazy range generator
JSintro Press Run to execute
for...of and spread both drive the same generator to produce [0,2,4,6,8] and [1,2,3,4], while the manual next() calls expose the raw protocol — two live values then {"done":true} (the value:undefined is dropped by JSON.stringify).