Es6 class with Iterator stops iterating at first yield

https://codepen.io/knackwurstbagel/pen/PgOOdq

I have been reading over the MDN topic of Iterators as well as other sites on this topic and It seems no-mater what I try, my iterator only yields an empty string and does not give me any values beyond this point.

I have tried debugging in ndb but it jumps me into the JavaScript core, how do I debug a iterator? What am I doing wrong?

First, remove the * before [Symbol.iterator], since you’re not using a generator for the iterator.

Then the code that updates the sum should be inside the next function. Otherwise it will not get updated and you might get an infinite loop.

Then the next function doesn’t recognize this.limit, because next is not this-bound to Fib. Define next as an arrow function instead.

1 Like

@kevcomedia Thank you this answers some questions I had. I was wondering about the * and weather it was necessary. I made the changes you recommended and It now works inside of ndb however in codepen it causes the page to lockup every time. I updated the saved version of what is working inside of node debugger and pasted that into the codepen. Any ideas why the page now locks up (prob infinite loop?)

I don’t get any lockups though… Did you update it?

1 Like

I just checked and indeed it seems to be working now without lockups, I might have made a minor change but perhaps I just needed to close the page and reopen it.

@kevcomedia Thank you very much for helping me solve this, and better understand iterators. I greatly appreciate this as I have been struggling for hours.