Finding a "safety syntax" for classes

Axel Rauschmayer axel at rauschma.de
Sat Mar 24 23:57:47 PDT 2012


One thing that I still would add (and haven't seen mentioned in the proposal) are computed property names. Manually creating private names is not a problem, neither is using this[] to add private instance data properties. But having to add private methods externally to the class declaration would be cumbersome.


[[[Sent from a mobile device. Please forgive brevity and typos.]]]

Dr. Axel Rauschmayer
axel at rauschma.de
Home: http://rauschma.de
Blog: http://2ality.com

On 25.03.2012, at 07:20, Allen Wirfs-Brock <allen at wirfs-brock.com> wrote:

> 
> On Mar 24, 2012, at 7:29 PM, Brendan Eich wrote:
> 
>> David Herman wrote:
>>> On Mar 24, 2012, at 3:01 PM, Nadav Shesek wrote:
>>> 
>>>> What about setting arbitrary expressions as the value for prototype methods? Being able to use higher-order functions to dynamically create functions is very important for functional style programming. I use it very often to decorate functions, compose functions together, set partially applied functions as methods, etc. It seems to be impossible with syntax proposed here - I think adding it to the "safety syntax" is very much needed and should not be over looked.
>>> 
>>> Yep, we already agreed to this -- see the grammar on Allen's "maximally minimal" proposal:
>>> 
>>>     http://wiki.ecmascript.org/doku.php?id=strawman:maximally_minimal_classes#class_declarations_and_expressions
>> 
>> I don't see what I read Nadav as asking for: the ability to initialize a prototype method from an arbitrary expression. What am I missing?
> 
> I suspect Dave misinterpreted Nadav's question.  So did I, when I originally read it.
> 
> The "superclass" can be set to an arbitrary AssignmentExpression.  This permits using a higher-order functions to be to define the [[Prototype]] of the class' prototype object. Potentially this mechanisms might be used to essentially have the effect of injecting dynamically generated methods into the class definition.  However, they would be inherited methods of the prototype object rather than own methods, although that may not matter.
> 
> To actually add a computed function as the value of a prototype object property within the class definition is pretty much the same thing as defining an arbitrary valued  prototype data property.  Defining non-method prototype properties is one of the features that we have previous been unable to reach consensus on and for that reason was intentionally excluded from the maximal-minimal proposal. As the proposal says:
> 
> "There is (intentionally) no direct declarative way to define either prototype data properties (other than methods) class properties, or instance property"
> "Class properties and prototype data properties need be created outside the declaration."
> 
> 
> Allen
> 
> 
> 
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120325/9e8ae529/attachment.html>


More information about the es-discuss mailing list