SOURCE


function *foo(x) {
    var y = 2 * (yield (x + 1));
    var z = yield (y / 3);
    return (x + y + z);
}

var it = foo( 5 );
// 启动generator,传入值会被忽略,传出值为第一个yield表达式的计算值
console.log( it.next().value);
// 传入值为12,将第一个yield表达式的值设为12, 
// 传出值为第二个yield表达式的计算值
console.log( it.next( 12 ).value);
// 传入值为13, 将第二个yield表达式的值设为13,
// 传出值为return的结果:
// x = 5
// y = 2*12 =24
// z = 13
console.log( it.next( 13 ).value);
console 命令行工具 X clear

                    
>
console