concept next method in category javascript

This is an excerpt from Manning's book Secrets of the JavaScript Ninja, Second Edition.
In this case, the first call to the iterator’s next method executes the generator code to the first yield expression, yield "Katana", and returns an object with the property value set to Katana and the property done set to false, signaling that there are more values to produce.
Another interesting thing happens when we call the next method on the iterator:
const result1 = ninjaIterator.next();If this was a standard straightforward function call, this would cause the creation of a new next() execution context item, which would be placed on the stack. But as you might have noticed, generators are anything but standard, and a call to the next method of an iterator behaves a lot differently. It reactivates the matching execution context, in this case, the NinjaGenerator context, and places it on top of the stack, continuing the execution where it left off, as shown in figure 6.8.
Listing 6.8. Sending data to and receiving data from a generator
function* NinjaGenerator(action) { #A const imposter = yield ("Hattori " + action); #B assert(imposter === "Hanzo", #C "The generator has been infiltrated"); #C yield ("Yoshi (" + imposter + ") " + action); } const ninjaIterator = NinjaGenerator("skulk"); #D const result1 = ninjaIterator.next(); #E assert(result1.value === "Hattori skulk", "Hattori is skulking"); #E const result2 = ninjaIterator.next("Hanzo"); #F assert(result2.value === "Yoshi (Hanzo) skulk", #F "We have an imposter!"); #F #A - A generator can receive standard arguments, like any other function. #B - The magic happens. By yielding a value, the generator returns an intermediary calculation. By calling the iterator’s next method with an argument, we send data back to the generator. #C - The value sent over next becomes the value of the yielded expression, so our imposter is Hanzo. #D - Normal argument passing #E - Triggers the execution of the generator and checks that we get the correct value #F - Sends data to the generator as an argument to the next method and checks whether the value was correctly transferred !@%STYLE%@! {"css":"{\"css\": \"font-weight: bold;\"}","target":"[]"} !@%STYLE%@!