Consider this generator function.
Why is the argument of the first call to .next()
essentially lost? It will yield and log each of the letter strings but skips "A"
. Can someone offer an explanation. Please advise on a way that I can access each argument each argument of the .next()
method and store it in an array within the generator function?
function* gen(arg) {
let argumentsPassedIn = [];
while (true) {
console.log(argumentsPassedIn);
arg = yield arg;
argumentsPassedIn.push(arg);
}
}
const g = gen();
g.next("A"); // ??
g.next("B");
g.next("C");
g.next("D");
g.next("E");