2 ms·
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 creat
by interesthrow2 8y 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/Guide/Iterators_and_Generators https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guid...
- eithed 8y agoI think that's no longer getter-getter and the example was to show a function that explicitly returns a function.