3 ms·
I couldn't find information why generator functions in JS require '*' in the syntax (ES6 spec/wiki just states this as a fact, but no rationale). Does anybody k
by pornel 13y ago
I couldn't find information why generator functions in JS require '*' in the syntax (ES6 spec/wiki just states this as a fact, but no rationale). Does anybody know?
Python manages to work fine without ugly wart in the syntax, and it seems to me that presence of `yield` keyword in body is enough at syntactical level to tell compiler that the function is a generator.
- bnjmn 13y agoIt means you can have generator functions that contain no yield statements, which is not as crazy as it sounds. I've had to do `if False: yield` before in Python to trick the language into treating a function as a generator. An unyielding generator behaves so differently from a similar-looking non-generator function that the extra syntax seems more than appropriate to me. The asterisk also makes it trivial (using regular expressions) to tell whether a string of code contains any generator functions. "Explicit is better than implicit" is a rule of thumb that Python supposedly values, but neglects to follow here!