SOURCE

function generators(arr) {
    let i = 0;
    return {
        next: function () {
            let none = i < arr.length;
            let value = none ? arr[i++] : "undefined";
            return {
                value,
                none: !none
            }
        }
    }
}

var iter = generators([1, 2, 3])
console.log(iter.next());
console.log(iter.next());
console.log(iter.next());
console.log(iter.next());
console.log(iter.next());
console 命令行工具 X clear

                    
>
console