📜  js 生成器 - Javascript 代码示例

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

代码示例1
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)