Can someone explain to me: why are generator functions in ES6 marked by asterisk symbol?
For example, instead of:
Empty generators (with no body) are not disallowed; so should unStarredFunc() follow generator semantics or not?
For compatibility reasons:
function yield(x) { return x };
function a() {
yield (4+1);
};
this is syntactically correct but calling .next() would result in an error whereas adding an asterisk to explicitly define a generator would cause .next().value === 5
detect that someGenerator contains yield operator at parse time
Some constructs cannot be resolved at parse time:
function someGenerator(i) {
if (glob)
return 4;
else
yield* anotherGen(i);
}
And of course its simpler to see immediately from the function* definition that its a generator without needing to dig into its source to look for yields.