new instantiation design alternatives

Angel Java Lopez ajlopez2000 at gmail.com
Wed Sep 17 10:25:09 PDT 2014


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 <rossberg at google.com>
wrote:

> On 17 September 2014 19:04, Brendan Eich <brendan at 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 at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140917/22d6626a/attachment.html>


More information about the es-discuss mailing list