Classes: suggestions for improvement

Kam Kasravi kamkasravi at yahoo.com
Mon Jun 13 08:01:26 PDT 2011



On Jun 13, 2011, at 1:55 AM, Axel Rauschmayer <axel at rauschma.de> wrote:

> Excellent points, thanks! Wasn’t aware that Smalltalk did duck typing, but it must make things much more generic.
> 
> Note: IIRC, Self calls its prototypical instances “prototypes”. What JavaScript calls a prototype (both the relation and the objects forming the right-hand sides of such a relation) is called a parent in Self. But that does not affect your arguments.
> 
>> The correspondence is not quite that straight forward.  A prototype P, as used in self, does seem to frequently subsume the role of a class.  A constructor  generally corresponds to the copy method of such a prototype.
> 
> 
> Isn’t that the illusion that class literals aim to create? That a class is actually a single construct, an object C with a method construct() and that you can apply the new operator to that object? new C(x,y) would perform the following steps:
> 
> - Create a new instance o whose prototype is C.
> - Invoke o.construct(x,y)
> 
> Maybe "initialize" would be a better name than "construct", then.
> 
> Couldn’t that illusion be turned into how things are actually done?

Indeed a number of frameworks use 'initialize' for their 'ctor'. I imagine this has been 
heavily discussed within TC39, but perhaps some of the rational has not made es-discuss. 
Certain unused ascii characters may be a candidate, for example I believe C++ uses ~ for 
their destructor, analogously a '^' for the ctor might be a good replacement 
given its semantics in a regex (start of pattern). 

class Monster {
  ^(health) {
    private health = health
  }
}

I believe this still renders the grammar LR(1), 
however given the symbols used for 'concise object literal extensions' 
(http://wiki.ecmascript.org/doku.php?id=harmony:concise_object_literal_extensions) 
this may be too much.


> 
> -- 
> Dr. Axel Rauschmayer
> 
> axel at rauschma.de
> twitter.com/rauschma
> 
> home: rauschma.de
> blog: 2ality.com
> 
> 
> 
> _______________________________________________
> 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/20110613/a415694b/attachment.html>


More information about the es-discuss mailing list