Finding a "safety syntax" for classes

Russell Leggett russell.leggett at gmail.com
Tue Mar 20 12:36:48 PDT 2012


On Tue, Mar 20, 2012 at 3:30 PM, Kevin Smith <khs4473 at gmail.com> wrote:

> class Snake extends Animal {
>>>
>>>     constructor(name){
>>>
>>>         super(name);
>>>
>>>     }
>>>
>>> Another option here would be:
>
> class Snake extends Animal {
>     // Using "new" ; )
>     new(name) : super(name) {}
> };
>
> Note the call to the super constructor before the body of the constructor.
>  This is similar to C#.  The reason that we might want to go that way is
> because if we wanted to have instance initializers in the class body (a
> very common thing in class-based languages), then we'd want to maintain
> this order:
>
> 1.  Call superclass constructor
> 2.  Execute instance property initializers in text order
> 3.  Execute constructor body
>

Yeah - Java enforces this by making it an error if a call to super happens
after any other statement. I think it makes sense, but does it belong in
the safety syntax? Let's keep anything innovative out - that will
inevitably lead to controversy.

- Russ


>
> kevin
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120320/de6ff9d5/attachment.html>


More information about the es-discuss mailing list