Regarding: "... My understanding was that there is wide agreement that invoking constructors without 'new' should be discouraged, and that functions behaving differently for Call and Construct are considered a legacy anti-pattern..."
I AGREE I don't know all the story and forces to keep constructor support the "new" and "no-new" invocation. But I had the idea of "class MyClass... " in the new specification, was an opportunity to: - Give "class MyClass.. ." a clear behavior oriented to classes, without relic behavior - Leave "new MyFunction... " as usual, with all the power of "classic" JavaScript Something like: class MyClass extends .. { constructor(arg1, arg2) : base(arg1) { this.arg2 = arg2; } } where the "this" is already created, the base invocation is allowed only at beginning, and no "MyClass()" (no new) invocation allowed (maybe it can only detected at runtime, and raise an exception) But probably I cannot see all the landscape and the "compelling reasons" to support "with new/without new" constructors, yet Angel "Java" Lopez @ajlopez On Wed, Sep 17, 2014 at 2:15 PM, Andreas Rossberg <rossb...@google.com> wrote: > On 17 September 2014 19:04, Brendan Eich <bren...@mozilla.org> wrote: > > I agree with Domenic that any derived-class constructor that needs to > > allocate with specific arguments *and* that must distinguish new'ing from > > calling should have to write an if-else. That's a hard case, EIBTI, etc. > > I agree. In fact, I don't see a reason to make it even that simple. My > understanding was that there is wide agreement that invoking > constructors without 'new' should be discouraged, and that functions > behaving differently for Call and Construct are considered a legacy > anti-pattern. In the light of that, I'm stilling missing the > compelling reason to introduce new^ at all. In particular, since TDZ > for `this` allows you to make the distinction fairly easily even > without a new construct, if you are so inclined. > > /Andreas > _______________________________________________ > es-discuss mailing list > es-discuss@mozilla.org > https://mail.mozilla.org/listinfo/es-discuss >
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss