Classes: suggestions for improvement

Axel Rauschmayer axel at rauschma.de
Tue Jun 14 23:50:31 PDT 2011


Ah, cool, I hadn’t noticed that. I read
new SkinnedMesh.constructor(aGeo, aMat)
as
new SkinnedMesh().constructor(aGeo, aMat)
I also missed the following sentence in Allen’s proposal:
> BTW, I believe that somebody else recently on one of these threads also suggested allowing the new operator to be applied to any object so feel free to take credit.


I do agree that this beats inventing a new protocol. Very clever.


On Jun 15, 2011, at 8:35 , Brendan Eich wrote:

> On Jun 14, 2011, at 11:25 PM, Axel Rauschmayer wrote:
> 
>> Cool! That’s what I meant when I wrote the following:
>> 
>>> From: Axel Rauschmayer <axel at rauschma.de>
>>> Date: June 13, 2011 10:55:56 GMT+02:00
>>> To: Allen Wirfs-Brock <allen at wirfs-brock.com>, es-discuss <es-discuss at mozilla.org>
>>> Subject: Re: Classes: suggestions for improvement
>>> 
>>>> 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.
> 
> 
> Except we are still trying to sugar the prototypal pattern (but not name the constructor; rather, name the prototype). And the constructor property of the prototype is named 'constructor'.
> 
> Inventing a new protocol doesn't seem as good. We can't migrate constructor-function-with-.prototype property as directly; we have two protocols not one.
> 
> Yes, the "outer" object that's denoted by the "class name" is now the prototype, not the constructor. Even though we extend new and instanceof to avoid requiring '.constructor' suffixing, that dot and name may have to be manually suffixed otherwise -- to call super.constructor, to get at "class" methods and properties.
> 
> The loss of the manifest name for the abstraction denoting the constructor seems like the thing to discuss.
> 
> /be

-- 
Dr. Axel Rauschmayer

axel at rauschma.de
twitter.com/rauschma

home: rauschma.de
blog: 2ality.com



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110615/21073b30/attachment-0001.html>


More information about the es-discuss mailing list