生成器函數的函數聲明與調用

生成器函數的參數傳遞
生成器函數執行個體
// 1s後控制台輸出111 2s後控制台輸出222 3s後控制台輸出333
function one() {
setTimeout(() => {
console.log(111);
iterator.next();
},1000);
}
function two() {
setTimeout(() => {
console.log(222);
iterator.next();
},2000);
}
function three() {
setTimeout(() => {
console.log(333);
iterator.next();
},3000);
}
function * gen() {
yield one();
yield two();
yield three();
}
// 擷取疊代器對象
const iterator = gen();
iterator.next();