I agree, that's why I think it would have been better to throw if base constructors returned primitives different from undefined. It would have been inconsistent with the way normal old functions behave. But, currently, there are two other inconsistencies: there's an inconsistency between base class constructors and derived class constructors, and one between normal functions and derived class constructors. I would have preferred the first inconsistency (between base class constructors and normal functions).
On Thu, Mar 10, 2016 at 3:58 AM, Isiah Meadows <[email protected]> wrote: > Classes aren't intended to be value type factories, so I find this > unlikely to change. > > On Tue, Mar 8, 2016, 15:46 Raul-Sebastian Mihăilă <[email protected]> > wrote: > >> I see that in step 13 of the [[Construct]] method of ordinary functions ( >> https://tc39.github.io/ecma262/#sec-ecmascript-function-objects-construct-argumentslist-newtarget), >> the value resulted from the evaluation of the function body is checked and >> if the constructor is a derived constructor, the value cannot be a >> primitive different from undefined. Why isn't the same check performed if >> the constructor is a base constructor? >> >> Example of code that, when executed in the Chrome console, throws: >> >> ``` >> (function () { >> 'use strict'; >> >> class A { >> constructor() { >> return 4; >> } >> } >> >> class B extends A { >> constructor() { >> super(); >> >> return 2; >> } >> } >> >> new B(); >> })(); >> ``` >> _______________________________________________ >> es-discuss mailing list >> [email protected] >> https://mail.mozilla.org/listinfo/es-discuss >> >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

