generator method js code example
Example 1: javascript generator function
function* idMaker() {
var index = 0;
while (true)
yield index++;
}
var gen = idMaker();
console.log(gen.next().value);
console.log(gen.next().value);
console.log(gen.next().value);
console.log(gen.next().value);
Example 2: js generator
function* fibonacci() {
var a = yield 1;
yield a * 2;
}
var it = fibonacci();
console.log(it);
console.log(it.next());
console.log(it.send(10));
console.log(it.close());
console.log(it.next());