Luke Hoban wrote:
In the discussion of max/min classes at the March TC39 meeting, there
was support for minimal class syntax, but a couple concerns with
max/min classes in particular.

One category of concern is the (intentional) bare-bones nature of
max/min.  In this case though, I think it has been demonstrated that
additional concepts (class properties, privates, prototype
properties, etc.) can be added to max/min later, if and when
experience shows them to be needed.

The other category of concern is that max/min decides the core
syntactic use of the valuable 'class' reserved keyword in the
language.  Max/min chooses to use 'class' for a new kind of block
with a nested constructor, instead of as direct extensions of the
notion of constructor function.

I've raised the class as constructor alternative approach before, and
it's something that a few teams I've worked with inside Microsoft
have advocated.  Since a choice on approach for classes will decide
the foundation upon which the class keyword is used in the language
going forward, I did a writeup of the alternative syntactic approach
at
http://wiki.ecmascript.org/doku.php?id=strawman:minimal_classes_as_constructors
for comparison.

I just don't understand why you use class keyword here. This will work without any changes, as-is, with plain function keyword. After all, you just augment a constructor definition.

Herby

Here's one of the examples from the write-up:

     class SkinnedMesh(geometry, materials) extends THREE.Mesh(geometry, 
materials) {

       // properties on the instance object
       public identityMatrix = new THREE.Matrix4();
       public bones = [];
       public boneMatrices = [];

       // ... note, this is the constructor body, statements are allowed here

       // methods on the prototype object
       public update(camera) {
         // ...
         super.update();
       }
     }

Classes as constructors aims to align more closely with existing
'function' syntax, augmenting with the ability to declaratively
specify members of the class.  Importantly though, methods (and
accessors) defined in the class body are bound as prototype
properties, not instance properties.  This can lead to more succinct
classes in many cases, and keeps the notion that a class is primarily
a constructor function.

Luke


_______________________________________________ es-discuss mailing
list es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to