According to the documentation, it mentions that "You can also provide a parameter to the next method to send a value to the generator." But where exactly does it send this value to?
Let's consider these 3 different generator functions:
function* first() {
while(true) {
var value = yield null;
}
}
var g1 = first(); g1.next();
g1.next(1000); // yields null
function* second() {
var i = 0;
while (true) {
i += yield i;
}
}
var g2 = second(); g2.next();
g2.next(1000) // yields 1000
function* third(){
var index = 0;
while (true)
yield index++;
}
g3 = third();
g3.next();
g3.next(1000); // yields 1
In generators 3 and 1, it seems like the argument passed has no impact on the next
method. Why is this the case? How does generator 2 calculate its return value? And why does it seem to be influenced by the provided argument?