我不知道为什么iterator.next(4)
打印{值:6,完成:false}?为什么将4分配给变量first
?其背后的机制是什么?
function *createIterator() {
let first = yield 1;
let second = yield first + 2;
yield second + 3;
}
let iterator = createIterator();
console.log(iterator.next()); // "{ value: 1, done: false }"
console.log(iterator.next(4));// "{ value: 6, done: false }"
console.log(iterator.next(5));// "{ value: 8, done: false }"
console.log(iterator.next());