This commit is contained in:
Ilya Kantor 2019-11-13 22:15:43 +03:00
parent 74e603ad3f
commit f759f38544

View file

@ -343,7 +343,7 @@ generator.next(4); // --> pass the result into the generator
![](genYield2.svg)
1. The first call `generator.next()` is always without an argument. It starts the execution and returns the result of the first `yield "2+2=?"`. At this point the generator pauses the execution (still on that line).
1. The first call `generator.next()` should be always made without an argument (the argument is ignored if passed). It starts the execution and returns the result of the first `yield "2+2=?"`. At this point the generator pauses the execution, freezing itself on the line `(*)`.
2. Then, as shown at the picture above, the result of `yield` gets into the `question` variable in the calling code.
3. On `generator.next(4)`, the generator resumes, and `4` gets in as the result: `let result = 4`.