1function* idMaker() {
2 var index = 0;
3 while (true)
4 yield index++;
5}
6
7var gen = idMaker();
8
9console.log(gen.next().value); // 0
10console.log(gen.next().value); // 1
11console.log(gen.next().value); // 2
12console.log(gen.next().value); // 3
13// ...
1function* g(){ //or function *g(){}
2 console.log("First");
3 yield 1;
4 console.log("second");
5 yield 2;
6 console.log("third");
7}
8let generator=g();
9generator.next();
10generator.next();
1function* makeRangeIterator(start = 0, end = 100, step = 1) {
2 let iterationCount = 0;
3 for (let i = start; i < end; i += step) {
4 iterationCount++;
5 yield i;
6 }
7 return iterationCount;
8}