This commit is contained in:
Ilya Kantor 2019-11-13 22:18:15 +03:00
parent f759f38544
commit 120700e1f2

View file

@ -343,7 +343,7 @@ generator.next(4); // --> pass the result into the generator
![](genYield2.svg) ![](genYield2.svg)
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 `(*)`. 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, while staying on the line `(*)`.
2. Then, as shown at the picture above, the result of `yield` gets into the `question` variable in the calling code. 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`. 3. On `generator.next(4)`, the generator resumes, and `4` gets in as the result: `let result = 4`.