Finding a "safety syntax" for classes

Kevin Smith khs4473 at
Tue Mar 20 12:30:13 PDT 2012

> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list