相关疑难解决方法(0)

ES6生成器 - 第一个next()没有yield表达式的示例

对于ES6生成器,为什么这篇博文的作者说:

来自:http://davidwalsh.name/es6-generators

"第一个下一个(..)调用,我们不发送任何内容.为什么?因为没有收益表达式来接收我们传入的内容."

不是第一次it.next()打电话(yield (x + 1))?

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

var it = foo( 5 );

// note: not sending anything into `next()` here
console.log( it.next() );       // { value:6, done:false }
console.log( it.next( 12 ) );   // { value:8, done:false }
console.log( it.next( 13 ) );   // …
Run Code Online (Sandbox Code Playgroud)

javascript ecmascript-harmony ecmascript-6

3
推荐指数
1
解决办法
352
查看次数