The class operator: a bridge between object and function exemplers
David Flanagan
dflanagan at mozilla.com
Mon Nov 14 15:15:30 PST 2011
On 11/14/11 3:01 PM, Allen Wirfs-Brock wrote:
>
> On Nov 14, 2011, at 2:01 PM, Brendan Eich wrote:
>
>> On Nov 14, 2011, at 12:16 PM, Allen Wirfs-Brock wrote:
>>
>>> let Point = {
>>> x:0,
>>> y,0,
>>> constructor(x,y} {
>>> this.x=x;
>>> this.y=y;
>>> }
>>> }.constructor; //<----------- note added property reference
>>>
>>> let p = new Point(1,2); //new operator applied to a constructible
>>> function
>>
>> So can you spec operator new a bit? It tries [[Construct]] and if
>> missing, tries for a .constructor property that it calls on a fresh
>> instance of Object whose [[Prototype]] is the exemplar?
>
> Yup, that's essentially the semantics. I'm going to write up the
> object exemplar strawman which will cover this (and also instanceof).
>
I have a bad feeling about making 'new' work with both functions and
object exemplars. If we can have two different types of classes, we're
going to end up using typeof on our class objects to figure out what
kind of class they are. If I've got a value C from a library and I
think it is an object exemplar, but it is in fact a constructor
function, then 'class C' is going to return Function rather than C itself...
Object exemplars does not pave the cowpaths for classes: it creates a
new path and just smears out the concept of a class into something more
broad. I fear it will create confusion rather than " provide a terse
and declarative surface for those semantics so that programmer intent is
expressed instead of the underlying imperative machinery."
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20111114/a80ac8f1/attachment.html>
More information about the es-discuss
mailing list