📜  生成器函数 javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:49.052000             🧑  作者: Mango

代码示例4
function* fibonacci() {
  var a = yield 1;
  yield a * 2;
}

var it = fibonacci();
console.log(it);          // "Generator {  }"
console.log(it.next());   // 1
console.log(it.send(10)); // 20
console.log(it.close());  // undefined
console.log(it.next());   // throws StopIteration (as the generator is now closed)