Le 3 févr. 2014 à 19:39, Brandon Benvie <[email protected]> a écrit :
> On 2/3/2014 10:22 AM, Claude Pache wrote: >> Therefore, it would be nice if `return expression` would be statically >> forbidden in the `constructor` method when defined using the `class` syntax >> (but a bare `return` is fine, which slightly complicates the grammar). > > I like the motivation, but doing it as an early error is problematic (having > experienced a validator that differentiates between `return`, `return > undefined`, and `return void expr` and complains loudly). > > Instead I would suggest to throw an error at runtime if a class constructor > returns anything besides undefined when it is constructed. I don't see much advantage in being allowed to write `return someExpressionThatShouldYieldUndefined`. Indeed, you can always write `someExpressionThatShouldYieldUndefined; return`, or even: `if (someExpressionThatShouldYieldUndefined !== undefined) throw new TypeError; return`. Also, the problem, with runtime exception, is that we are no longer able to easily differentiate between `construct` methods that are defined using the `class` syntax and other `construct` methods... which raise the issue of backward compatibility. —Claude _______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

