class-private syntax in ES6 (was: ES6, ES7, ES8 and beyond. A Proposed Roadmap.)

Brendan Eich brendan at mozilla.com
Sun Apr 21 10:22:53 PDT 2013


Trimming cc: list to just es-discuss.

Mark S. Miller wrote:
>   * Completing the class design
>       - at least high integrity and private state

If I'm not mistaken, we need class-private syntax for classes to have 
ultimate double-blind consensus in *ES6*. See last meeting notes.

At JQueryUK, I threw up a sketch in slides based on 
http://wiki.ecmascript.org/doku.php?id=strawman:relationships:

|class  SkinnedMeshextends  THREE.Mesh{
   private  identityMatrix,
           bones,
           boneMatrices;

   constructor(geometry,  materials)  {
     super(geometry,  materials);

     this at identityMatrix=  new  THREE.Matrix4();
     this at bones=  [];
     this at boneMatrices=  [];
     ...
   }

   ...
}|


The TypeScript (CoffeeScript had it already, and more concisely via @) 
option to declare and initialize via a private prefix on one of 
constructor's parameters would be helpful to many developers:

|class  Point{
   constructor(private x, private y) {}
   add(other) {
     return Point(this at x + other at x, this at y + other at y);
   }
   ...
}
|


I hope we can agree to do this much for ES6, based on the relationships 
work, which I'd like to thank Tom and you for championing. At first I 
thought it was not helpful, but then the lightbulb went off ;-).

/be



More information about the es-discuss mailing list