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 |
'use strict'; const getIterableObject = (argMax = 10) => { const iterableObject = { [Symbol.iterator]: () => { let cnt = 0; const iterator = { next: () => { const value = cnt++; const done = (argMax <= value); const iteratorResult = { value, done }; return iteratorResult; }, }; return iterator; }, }; return iterableObject; }; for (const v of getIterableObject(3)) { console.log(v); } for (const v of getIterableObject(7)) { console.log(v); } |
1 2 3 4 5 6 7 8 9 10 |
0 1 2 0 1 2 3 4 5 6 |