'function *' is not mandatory

Brendan Eich brendan at mozilla.com
Sun Sep 1 09:56:50 PDT 2013


> Jussi Kalliokoski <mailto:jussi.kalliokoski at gmail.com>
> September 1, 2013 5:38 AM
> Sorry if this has been brought up before,

It has, even in this thread.

> but why `function *` (which looks like a pointer to a function more 
> than a generator

This is JS, please take off your C/C++ hat :-P.

> ) instead of something clearer, e.g. `generator myGenerator () {}`? I 
> see the obvious ASI hazard, but this can be mitigated by not allowing 
> unnamed generators, e.g. `{ myGenerator: generator _ () {} } `,

This doesn't work in general, it is backward-incompatible. If someone 
bound or assigned to generator in-scope, your proposed change could 
break compatibility -- or else require parsing to depend on name binding.

foo = generator
bar()
{}

Remember, if there wasn't an error, ASI doesn't apply. Trying to "patch" 
this bad theory with a [no LineTerminator here] restriction to the right 
of 'generator' does not work in the grammar without reserving 
'generator' -- we can't put that restriction to the right of every 
Identifier on the right of every expression production.

Please stamp this on all inner eyelids so I don't have to repeat it ad 
nauseum. Thanks!

/be



More information about the es-discuss mailing list