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
// ...
function* expandSpan(xStart, xLen, yStart, yLen) {
const xEnd = xStart + xLen;
const yEnd = yStart + yLen;
for (let x = xStart; x < xEnd; ++x) {
for (let y = yStart; y < yEnd; ++y) {
yield {x, y};
}
}
}
//this is code from my mario game I dont think this code is functional
// generator function in javascript
// The function* declaration (function keyword followed by an asterisk) defines a generator function, which returns a Generator object.
function* generator(i) {
yield i;
yield i + 10;
}
const gen = generator(10);
console.log(gen.next().value);
// expected output: 10
console.log(gen.next().value);
// expected output: 20
console.log(gen.next().value);
// expected output: undefined
function* name([param[, param[, ... param]]]) {
statements
}