生成器

function* nTimes(n){
    if(n>0){
        yield * nTimes(n-1);
        yield n-1;
    }
}
for(const x of nTimes(3)){
    console.log(x);
}

 

 

 

 

 

 

  •  for-of:在可迭代对象上创建一个迭代循环;
  • for-in:以任意顺序迭代某对象的可枚举属性

 

posted @ 2022-04-15 22:09  ˙鲨鱼辣椒ゝ  阅读(11)  评论(0)    收藏  举报