1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
'use strict'; const myGenerator = () => { const a = [100, 101, 102]; const innerGenerator = function* () { a.forEach((e) => { // yield e; // SyntaxError console.log(e); }); for (const e of a) { yield e; } }; return innerGenerator(); }; function* generator() { yield 1; yield 2; yield 3; } const generator4main = () => { const g = myGenerator(); for (const e of g) { console.log(e); } }; generator4main(); |
1 2 3 4 5 6 |
100 101 102 100 101 102 |