subclassof

P T Withington ptw at pobox.com
Mon Jan 18 13:05:40 PST 2010


On 2010-01-18, at 15:41, Mark S. Miller wrote:

> On Mon, Jan 18, 2010 at 7:32 AM, P T Withington <ptw at pobox.com> wrote:
> 
>> In the various classes-as-sugar proposals, is there a way to test if one
>> class is a subclass of another?  Is it as simple as:
>> 
>> classa.prototype instanceof classb
>> 
>> ?
>> 
>> In some of them, yes. For the desugaring presented at <
> https://mail.mozilla.org/pipermail/es-discuss/2008-August/006941.html>,
> 
>    WobblyPoint.prototype instanceof Point
> 
> would work for the right reason.

Yeah, I saw (and liked) that.

In OpenLaszlo we allow mixins (which are flattened into a single-inheritance prototype chain + multiple-inheritance interfaces), and we adopted the AS3 `is` operator, so we say:

  subclass.prototype is superclass

and superclass can be either a class or a mixin.  [Sadly this doesn't work in AS3!]
  
> In some later proposals, no, because the
> concept of subclassing is being replaced by the concept of trait
> combination. Since this gives non-tree-like subtype relationships, it can't
> accommodate instanceof.
> 
>> Should there be a `subclassof` operator?
>> 

Do you have a pointer to the later proposals?

I guess my question stands.  Even if I implement classes using traits, I would want to be able to ask if a class had a particular trait.  I guess that would have to be part of the class protocol then, not a language primitive.


More information about the es-discuss mailing list