如果你有类似的发电机,
function* f () {
// Before stuff.
let a = yield 1;
let b = yield 2;
return [a,b];
}
然后运行
var g = f();
// this question is over this value.
g.next(123); // returns: { value: 1, done: false }
g.next(456); // returns: { value: 2, done: false }
g.next(); // returns: { value: [ 456, undefined ], done: true }
第一次调用.next()
set a
to123
和第二次调用 set b
to 456
,但是最后一次调用.next()
this 是 return,
{ value: [ 456, undefined ], done: true }
难道第一次调用中的参数g.next
就迷路了?他们会发生什么?使用上面的例子,我该如何设置a
?