How to iterate over the results of a generator function

前端 未结 2 363
一向
一向 2021-01-12 23:40

Is there a better way to iterate over the results of a generator, my for loop is ugly:

for(let job = readyJob.next(); !job.done; job = readyJob.next()){ } 
<         


        
2条回答
  •  醉梦人生
    2021-01-13 00:25

    Yes, if your environment already supports for...of:

    for (var job of readyJob) {
      // ...
    }
    

    If not, have seen this a couple of times:

    var next;
    while (!(next = readyJob.next()).done) {
       var job = next.value;
       // ...
    }
    

提交回复
热议问题