Not that much easy. But we can do something like this
/** * @param val * @returns {Generator<*, void, *>} */ function* ourOwnInterable(val) { while (val < 3) { yield val; val++; } } /** * @type {Generator<*, void, *>} */ const iterator = ourOwnInterable(0); for (const el of iterator) { console.log(el); }
Hi
Wow im programming with javascript since like 4 years and i have never used nor seen those generator functions. So definitely thank you for this hint!
Always thought the usage of the asterisks in declarations is limited to pointers in c and c++ 😅
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Not that much easy.
But we can do something like this
Hi
Wow im programming with javascript since like 4 years and i have never used nor seen those generator functions. So definitely thank you for this hint!
Always thought the usage of the asterisks in declarations is limited to pointers in c and c++ 😅