Can someone explain to me: why are generator functions in ES6 marked by asterisk symbol?
For example, instead of:
function *someGenerator() {
yield 1;
yield 2;
yield 3;
}
we could write:
function someGenerator() {
yield 1;
yield 2;
yield 3;
}
or even:
var someGenerator = () => {
yield 1;
yield 2;
yield 3;
}
var someObject = {
someGenerator() {
yield 1;
yield 2;
yield 3;
}
}
The JS compiler can detect that someGenerator
contains yield
operator at the parse time and make a generator from this function.
Why is detection of yield
existence not enough?