SOURCE

function *test1(){
    return 'test';
}
const t1 = test1()
console.log(t1.next());

function *test2(){
    yield;
}
const t2 = test2();
console.log(t2.next());
console.log(t2.next());

function *test3(){
    console.log('test3 console1');
    yield 'yield1';

    console.log('test3 console2');
    yield 'yield2';

    console.log('test3 console3');
    yield 'yield3';

    console.log('return');
    return 'return';
}
const t3 = test3();

for(const x of t3){
    console.log(x);
}

function *test4(param){
    console.log(param);
    console.log(yield);
    console.log(yield);
}

const t4 = test4('t4_1');
console.log(t4.next('t4_2'));
console.log(t4.next('t4_3'));
console.log(t4.next('t4_4'));


//yield*  会将可序列化对象序列化成单独输出的值
function *test5(){
    yield 2;
    yield * 'test5'
    yield 1
}
for(const x of test5()){
    console.log(x);
}

console.log('///////////////////////////////////////')
//递归
function *nTimes(n){
    if(n>0){
        yield* nTimes(n-1);
        yield n-1;
    }
}

for(const x of nTimes(3)){
    console.log(x);
}


console.log('11111111111111111111111111111111111');
function *test6(){
    yield '1'
    yield '2'
    yield '3'
}

const t6 = test6();

console.log(t6.next());
console.log(t6.return());
console.log(t6.next());
console 命令行工具 X clear

                    
>
console