What does the syntax * (asterisk / asterisk) mean after reaching the damage in the recursive function of the generator?

Let's say I created an ES6 generator

function *createFibonacciIterator(a = 0, b = 1) {
  yield b;
  yield *createFib(b, b + a); // <== QUESTION IS ABOUT THIS LINE
}

Then I use this generator to get the first 20 results.

let fibber = createFibonacciIterator();
for (let ii = 0; ii < 20; ii++) {
    console.log(fibber.next());
}

If I leave *the line yield *createFib(b, b + a);, things will break, which makes sense, because I do not want to give an iterator, but the actual value.

What is the technical meaning of *the generator?

+4
source share
2 answers

When *used in an ad function, it means that it is a generator function.

yield *myGeneratorFunction(), Ecmascript 262, 14.4.14, , , next() , .

yield * (, yield createFibonacci()), . , createFibonacci.

+2
yield *smth;

,

for (let x of smth) {
  yield x;
}
0

All Articles