generator真好玩,就是没啥用。。
// generator实现斐波那契
function* fibonacci() {
let [a, b] = [0, 1];
while (true) {
yield b;
[a, b] = [b, a + b];
}
}
let gen = fibonacci();
function sleep(sleepTime) {
setTimeout(() => {
it.next()
}, sleepTime)
}
function* main() {
while (true) {
console.log(gen.next());
yield sleep(1000)
}
}
const it = main()
it.next()