The first call to next() is a special case where any argument passed to it is lost. Because arguments passed to next() become the values returned by yield, an argument from the first call to next() could only replace the first yield statement in the generator function if it could be accessed before that yield statement. That’s not possible, so there’s no reason to pass an
argument the first time next() is called.
function* iterator() { let x; let first = yield x + 12; let second = yield first + 1; yield second + 3;}let obj = iterator();console.log(obj.next(1)) //{ value: NaN, done: false }
--
You received this message because you are subscribed to the Google Groups "Zakas Books" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zakasbooks+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
arguments passed to next() become the values returned
by yield,
function* iterator() { let first = yield 12;
let second = yield first + 1; yield second + 3;}let obj = iterator();
console.log(obj.next()) // 12
console.log(obj.next()) // NaN again