The purpose / real usage example of sending value to es6 next(myParameter)?

19 views
Skip to first unread message

Vladimir Kelman

unread,
Jun 2, 2016, 6:34:50 AM6/2/16
to Exploring ES6

I understand that with ES6 generators we can send a value to generator using next(myParameter). Could someone provide a realistic example showing why is it necessary / helpful?

Axel Rauschmayer

unread,
Jun 2, 2016, 6:41:18 AM6/2/16
to Exploring ES6

Vladimir Kelman

unread,
Jun 2, 2016, 8:02:08 AM6/2/16
to Exploring ES6
Thank you Axel.

I'm new to this stuff and was trying to understand how next(myParameter) works and why it is necessary.
I also found it on mozilla dev documentation and now understand it:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators - "fibonacci generator using next(x) to restart the sequence" example.
"The next() method also accepts a value which can be used to modify the internal state of the generator. A value passed to next() will be treated as the result of the last yield expression that paused the generator."

Axel Rauschmayer

unread,
Jun 2, 2016, 8:03:48 AM6/2/16
to Exploring ES6
If you are new to generators, you can read the following section in “Exploring ES6”: http://exploringjs.com/es6/ch_generators.html#_generators-as-observers-data-consumption
Reply all
Reply to author
Forward
0 new messages