// 斐波拉切数列
function* fabs(){
let a = 1;
let b = 1;
while(true) {
yield a;
[a, b] = [b, a + b];
}
}
const myArr = fabs();
// 方式1
myArr.next(); // 1
myArr.next(); // 1
myArr.next(); // 2
myArr.next(); // 3
myArr.next(); // 5
myArr.next(); // 8
const [first, second, third, fourth, fifth, sixth] = fabs();
sixth // 8
网友评论