The class operator: a bridge between object and function exemplers

Brendan Eich brendan at mozilla.com
Mon Nov 14 18:56:10 PST 2011


On Nov 14, 2011, at 6:47 PM, Axel Rauschmayer wrote:

>>> Is a dual role even necessary? Why not stick to just class declaration? Looking through the eyes of an outsider, class { ... } looks like a class declaration. Given that we already have typeof and instanceof, wouldn’t an outsider expect a name such as classof? Furthermore, if object exemplars and function exemplars are to exist in parallel. Then:
>>> 
>>>      function Foo() {};
>>>      var f = new Foo();
>>>      classof f === Foo // true
>>> 
>>>      let Foo = {};
>>>      var f = new Foo();
>> 
>> This could succeed, due to 'constructor' inherited from Object.prototype. But, it could fail if we require an own constructor, or at least an inherited one whose value is a function object (or callable object if host) whose .prototpye is the exemplar.
>> 
>>>      classof f === Foo // true
>> 
>> If new Foo() throws, you won't reach here, and all is consistent.
> 
> 
> Sorry, mucked it up (shouldn’t email when tired):
> 
>      let Foo = { constructor: function() {} }; // or any valid object exemplar on the RHS, really
>      var f = new Foo();
>      classof f === Foo // true

In that case class f === f.constructor && f.constructor === Foo per Allen's last post about this wiring.

/be

> 
> -- 
> Dr. Axel Rauschmayer
> axel at rauschma.de
> 
> home: rauschma.de
> twitter: twitter.com/rauschma
> blog: 2ality.com
> 
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20111114/921567c3/attachment.html>


More information about the es-discuss mailing list