Q:

function generator js

function* name([param[, param[, ... param]]]) {
   statements
}
1
function* idMaker() {
  var index = 0;
  while (true)
    yield index++;
}

var gen = idMaker();

console.log(gen.next().value); // 0
console.log(gen.next().value); // 1
console.log(gen.next().value); // 2
console.log(gen.next().value); // 3
// ...
0

New to Communities?

Join the community