Generator
和yield
的基本使用
function* fn() {
console.log('pause' + (yield 1));
yield 2;
yield console.log('hhh');
}
let test = fn();
console.log(test.next()); //{value: 1, done: false}
console.log(test.next()); //pauseundefined {value: 2, done: false}
console.log(test.next()); //hhh {value: undefined, done: false}
2024/3/19大约 2 分钟