Finding a "safety syntax" for classes

Russell Leggett russell.leggett at gmail.com
Wed Mar 21 07:35:50 PDT 2012


On Wed, Mar 21, 2012 at 9:35 AM, Kevin Smith <khs4473 at gmail.com> wrote:

> Hi Axel,
>
> We should probably hold off on private and static member syntax until
> there's consensus on the other open issues:
>

Yeah, we can't add any features on the safety syntax, we'll get back to
where we started. Kevin summarized the remaining issues really well, and
they seem very tractable with a little debate.


>
> - "constructor" vs. "new" (Dave and I say "new", Allen says "constructor";
>  mostly aesthetic - can be put off for now)
>

I've thought about it and I'm pretty solid on constructor now:

   1. I think its easier to explain - it will actually result in a
   constructor on the prototype.
   2. The actual constructor function and the .constructor property really
   should always be in sync - this helps with that.
   3. "new" doesn't have those benefits - people might expect to be able to
   call .new() like in ruby.
   4. "new" conflicts with the new <object> proposal.



> - class-side inheritance?  (Mark and I say no, Allen and Russell say yes)
>
- What restrictions for RHS of "extends"?  Must it be a constructor?
>  (Russell and I say yes)
>
>
I've already made my arguments here


> Additionally, I'm still worried about how we call the superclass
> constructor:
>
>     new() {
>         // do arbitrary stuff here
>         super(...);
>     }
>
> This would potentially allow a superclass instance method to be called
> before the superclass initialization has completed.  If we want to maintain
> the invariant (as it seems most class-based languages do) that methods can
> only be called after initialization has completed, then this won't work.
>  Thoughts?
>

I think that's ok. Just like I don't think there should be an implicit
super call at the top of the constructor if you skip it. Sure Java and C#
enforce this, but I don't think its really the JavaScript style. There are
realistic use cases for doing something before you call super, or skipping
a call to super. It is also something that can easily be caught by a linter
or IDE as a warning.

- Russ


>
> kevin
>
> _______________________________________________
> 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/20120321/b7edb981/attachment.html>


More information about the es-discuss mailing list