In ES6, what happens to the arguments in the first call to an iterator's `next` method?

后端 未结 3 1558
暖寄归人
暖寄归人 2020-12-06 13:17

If you have an generator like,

function* f () {
  // Before stuff.
  let a = yield 1;
  let b = yield 2;
  return [a,b];
}

And, then run

3条回答
  •  醉话见心
    2020-12-06 14:14

    Try:

    var g = f();
    // this question is over this value.
    g.next(); // returns: { value: 1, done: false }
    g.next(123); // returns: { value: 2, done: false }
    g.next(456); // returns: { value: [123, 456], done: true }
    

提交回复
热议问题