Generator in ES6
some examples of iterators and generators in ES6
JavaScript
//Yield
function *foo(x) {
yield "one";
yield "two";
return "three"
}
var it = foo( 5 );
// note: not sending anything into `next()` here
console.log( it.next() );
console.log( it.next() );
console.log( it.next() );
console.log( it.next() );
console.log( it.next() );