SOURCE

function iteratorGenerator(list) {
    let idx = 0;
    const length = list.length;
    return {
        next: function () {
            const done = idx >= length;
            const value = !done ? list[idx++] : undefined;
            return {
                done,
                value
            }
        }
    }
};

const iterator = iteratorGenerator(['1号', '2号', '3号']);
console.log(iterator.next());
console.log(iterator.next());
console.log(iterator.next());
console.log(iterator.next());
console 命令行工具 X clear

                    
>
console