Re: new

Sun, 16 Oct 2011 12:51:21 -0700

> From: Allen Wirfs-Brock <[email protected]>
> Subject: Re: new <Object>
> Date: October 11, 2011 23:50:14 GMT+02:00
> To: Jake Verbaten <[email protected]>
> Cc: es-discuss <[email protected]>
> 
> It's still on my radar.  Most recently see 
> https://mail.mozilla.org/pipermail/es-discuss/2011-September/016736.html 
> 
> It isn't an accepted Es.next proposal, but I suspect there is wiggle room for 
> it to slip in as part of the enhanced object literals/class support if there 
> is sufficient interest.
> 
> I haven't pushed it too hard yet because I think we have more pressing issues 
> to get resolved and I didn't want this to become a distraction.  However, I 
> probably should write up a strawman for it.


A few ideas, also in the vein of “not wanting this to be a distraction”:

- I would feel better about “instantiable prototypes” (IPs) if there was a 
clean migration path. Then people could start using IPs and it wouldn’t matter 
whether the standard classes were constructors or IPs. See check list, below.
- What will happen to class methods? That’s the only advantage that 
constructors currently have. But I’ve always felt uneasy about them (they felt 
to Java-ish where they are used to mimic functions). I suspect that most of 
these methods are better put into a module (especially Object.*).
- Wish – factory methods that can return subclasses. Not sure how that fits 
into the picture; it’s possible that using a function is fine as a work-around.
- Wish – named constructors. For that, it would be nice if we could have 
syntactic sugar such as
     new Point.zero()
  meaning that Point is just instantiated and then zero() initializes it. With 
that notation, new Point(...) actually means
     new Point.constructor(…)
  I know that this would wreak havoc with legacy compatibility, but maybe there 
is a similar solution that would not.


Check list of mechanisms that need to generic.
- “new” works the same for IPs and constructors.
- “instanceof” needs a similarly generic definition.
- Subclassing. There is no need to let a constructor “subclass” a prototype, 
but the inverse should be doable. Then <| won’t work. Instead, maybe a method 
that is used in both cases?

MyConstructor.extendedBy(function(...) {…});
MyConstructor.extendedBy({…});
MyPrototype.extendedBy({…});

Alternatively, the following
    MyConstructor <| { … }
could be syntactic sugar for
    MyConstructor.prototype <| { … }

Rationale: Would a function ever be a prototype of something else but a 
function? Thus, if the RHS is not a function, it desugars in the above manner.

-- 
Dr. Axel Rauschmayer

[email protected]
twitter.com/rauschma

home: rauschma.de
blog: 2ality.com



_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to