Hacker News new | ask | show | jobs
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...

1 comments

I think that's no longer getter-getter and the example was to show a function that explicitly returns a function.