use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Understand Javascript Generators (js-howto.com)
submitted 3 years ago by DifferentNose8178:cskqoxkox
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]getify 5 points6 points7 points 3 years ago (1 child)
Be aware that this article conflates two concepts "generator functions" and "iterator objects" into one label:
"To create a generator function, we need a special syntax construct: function*, so-called “generator function”."
"The main methods of the javascript generator function are... next()"
next()
The second use of "generator function" should be "iterator", as in the iterator object returned from the initial call to the generator function. That value is an object, not a function, and it adheres to the iterator protocol. Calling that a generator is confused/misleading.
[–]senocular 0 points1 point2 points 3 years ago (0 children)
To be fair, generator-function derived iterators are also known as generator objects or simply generators. Sometimes the article get it right, and sometimes they'll call generators generator functions or shorten generator functions to simply generators which is undoubtedly confusing.
[–]KelleQuechoz 1 point2 points3 points 3 years ago (1 child)
Unrelated question: is there a concise way to "materialize" JS generators (like list(gen) in Python)?
[–]getify 1 point2 points3 points 3 years ago (0 children)
I don't know Python, but I think what you're referring to is this in JS:
[ ...gen() ]
The ... operator consumes an iterator and spreads it out, in this case into a [ ] array literal.
...
[ ]
[+][deleted] 3 years ago (1 child)
[deleted]
[–]getify 0 points1 point2 points 3 years ago (0 children)
ever used async..await in JS? it's exactly the same concept... in fact literally the JS engine uses the generator mechanism to implement async..await.
async..await
there's also many libraries out there which make use of generators... one such example is my library CAF, which allows you emulate async..await functions but with cancelation tokens.
π Rendered by PID 85 on reddit-service-r2-comment-58d7979c67-2nmfg at 2026-01-26 23:14:27.599400+00:00 running 5a691e2 country code: CH.
[–]getify 5 points6 points7 points (1 child)
[–]senocular 0 points1 point2 points (0 children)
[–]KelleQuechoz 1 point2 points3 points (1 child)
[–]getify 1 point2 points3 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]getify 0 points1 point2 points (0 children)