Generator * syntax

# joe (11 years ago)

Is the function* syntax for generators final? I'm curious what the justification for it is, but mostly I just need to know if it's likely to change.

# Rick Waldron (11 years ago)

On Mon, Mar 3, 2014 at 6:44 PM, joe <joeedh at gmail.com> wrote:

Is the function* syntax for generators final?

Yes

I'm curious what the justification for it is,

The yield keyword was previously only reserved in strict mode (ES5 7.6.1.2), which means it's perfectly valid JS to have: function f() { var yield = 1; return yield; } in non-strict mode code. In order to allow generator functions in both strict and non-strict code, where yield is a keyword, a new syntactic form was needed, ie. the star (generator) function. This avoids potentially breaking any existing code that is using yield as an identifier.

but mostly I just need to know if it's likely to change.

I'm confident that it will not change.

# Marcus Stade (11 years ago)

Does this mean that the body of a generator function is strict mode, or just that yield is reserved?

# Allen Wirfs-Brock (11 years ago)

On Mar 23, 2014, at 9:59 AM, Marcus Stade wrote:

Does this mean that the body of a generator function is strict mode, or just that yield is reserved?

No, but within generator functions 'yield' is always interpreted as the yield operator.