>> So you don’t think the two roles clash semantically? (1) “Turn an object 
>> exemplar into a class” versus (2) “get the class of an object”. Both are 
>> definitely useful! But that they can be performed by the same operator seems 
>> like a happy coincidence. If (1) was to be further refined, e.g., as Brendan 
>> suggested, by throwing an exception if an object exemplar does not have a 
>> "constructor" method then it seems both roles would drift further apart. I’m 
>> mainly arguing for a clear separation of concerns.
> 
> The two roles are the same!

=== Role 1 ===

> The value of the constructor property of an object exemplar is a function 
> exemplar (AKA class exemplar)  whose prototype property's value is the object 
> exemplar. When you say:
>      let P = class {constructor() {} };
> You aren't turning an object exemplar into a class exemplar your are simply 
> accessing the class exemplar that is explicitly defined  as part of  the 
> object exemplar.
> 
> The above let is also equivalent to:
> 
>    let PrototypalP = {constructor(){} };
>    let P = class PrototypalP;
> 
> which is equivalent to:
> 
>    let P = class  {constructor(){} };
>    let PrototypalP = P.prototype;

=== Role 2 ===

> Finally, when I talk about an object's constructor I include the possibility 
> that 'constructor' is inherited, so the above identifies only hold when an 
> own constructor property is explicitly provided.  In fact, that is really 
> what I mean by an object exemplar
> 
>    var foo = { };
>    class foo is Object;   //true
>    ??? Object.prototype is foo;  //also true
> 
>    bar = new foo;  //same as new foo.constructor which is the same as new 
> Object
>    class bar is class foo;   //and both === Object.
>   
> It all falls out of the plumbing.

That makes sense (apart from the line marked with ???).

I like to have a human language, intuitive description for what an operator 
does. How about the following one for `class`?

     “Retrieve the class (function exemplar) of the operand”
      or “go to the nearest class” [in the case of an object exemplar, the 
nearest class is inside the exemplar]

But the description is *not* “determine the constructor function that created 
the operand”.

-- 
Dr. Axel Rauschmayer
a...@rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com



_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to