The class operator: a bridge between object and function exemplers

Allen Wirfs-Brock allen at wirfs-brock.com
Mon Nov 14 14:18:31 PST 2011


On Nov 14, 2011, at 1:06 PM, Axel Rauschmayer wrote:

> This is the middle ground between class proponents and object exemplar proponents, right?

Yes, next up is to write-up a stawman that ties all the pieces together into a rational story/

> 
> - Object exemplar proponents get object literal syntax, but will still have to use MyClass.prototype (e.g. to add methods) after having declared a class.

or they just use the pure object exemplar pattern with the class operator:

let Point = {
     x:0,
     y,0,
     offsetBy(aPoint) {return new Point(this.x+aPoint.x, this.y+aPoint.y},  //<---- a method
     constructor(x,y} {
         this.x=x;
         this.y=y;
     }
};


> 
> - Class proponents get syntax that looks like some of the class declaration proposals, but don’t get a “proper” class construct.

I would say that we are avoiding adding any new declarations (other than let and const which are really all we need);  

> 
> Given that backward compatibility is a major issue, the proposal sounds reasonable. It also nicely settles the syntax debates surrounding class declarations. As “class declaration light”, it probably makes neither party completely happy, but maybe that’s what is called for.
> 

We can't make ES into a pure class-based language such as Dart (and many wouldn't want to) so whatever we do has to place well with what it already there and also the various different abstraction styles that different sub-communities  have developed.  Hopefully we can  get past these debates an provide a good solution that uniquely builds upon the deep foundations JavaScript 

allen


More information about the es-discuss mailing list