|
|
|
|
|
by interesthrow2
2745 days ago
|
|
Or as an alternative one can use a generator, they are built for that purpose AND are supported by a wide range of other JS constructs without any need to create iterators manually and all that. function * getNext(){
let i = 2;
while(true){
i = i * 2;
yield i;
}
}
Here, no closure needed.https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guid... |
|