Finding a "safety syntax" for classes
allen at wirfs-brock.com
Sat Mar 24 22:20:23 PDT 2012
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:
> 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."
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss