Ticker

6/recent/ticker-posts

Ad Code

Responsive Advertisement

js yield递归问题

// 创造一个可迭代对象并返回递增的整数
function* nTimes(n) {
    if (n > 0) {
        yield* nTimes(n - 1);
        yield n - 1;
    }
}

for (const x of nTimes(3)){
    console.log(x);
}
// 0
// 1
// 2

这里yield 是怎么操作的,能解释下吗,
最好流程分解一下;;

我弄明白了,不需要回答了

Enregistrer un commentaire

0 Commentaires