Now and then, JavaScript quietly teaches me something, sitting under the surface. Recently, that lesson came from a tiny custom iterator I was writ...
For further actions, you may consider blocking this person and/or reporting abuse
Nice post.
While there is the generator function syntax you used normal functions to achieve this. This also explains what generators do under the hood.
I appreciate that.
Please enable syntax highlighting for your code blocks. It makes everything so much easier to read.
Thank you.
Exactly, writing it without generators helped me understand why they behave the way they do.
And yes, totally agree on syntax highlighting, I’ll fix that.
This is a great example of how structure quietly defines behavior in JavaScript.
What I really like here is that the post doesn’t frame this as a “gotcha”, but as a design choice: where state lives determines whether something is consumable, reusable, or intentionally single-shot. That’s not a JS quirk — it’s a fundamental engineering lever.
Once you see this, closures stop feeling magical and start feeling architectural. You’re not just writing functions anymore, you’re defining lifetimes and invariants. Generators, pipes, middleware — same rule, different surface.
This kind of mental model is exactly what separates “it works” code from code you can reason about six months later. Really well explained.
Thank you. Seeing closures as an architectural choice rather than magic was the big shift for me too.
Great post
Thank you.
Awesome and clear!
Thank you.
As you continue "evolving" this work (well done, btw), you end up rediscovering something like IxJS or something even more powerful and useful such as Observables. RxJS will open up a whole world of possibilities once you discover it, let alone if you combine it with Rimmel.js for the UI...
Thanks!
I’ve heard of RxJS but never really explored it properly.
Looks like I’m slowly walking in that direction without realising.
Will definitely check out RxJS, IxJS and Rimmel.js too, thanks for the pointers!
Wow, this was a super clear explanation — I really enjoyed how you broke down the closure pattern with simple examples. Great insight, and it actually made me rethink how I structure functions!
So happy to hear that.
I’ve always felt JS explanations jump straight into theory, so I tried keeping it real with small examples.
Glad it helped you.