Must built-in prototypes also be valid instances? (Was: Why DataView.prototype object's [[Class]] is "Object"?)

Allen Wirfs-Brock allen at wirfs-brock.com
Mon Oct 1 13:20:35 PDT 2012


On Oct 1, 2012, at 12:21 PM, Brendan Eich wrote:
...
> The best reason for using Object is the one Mark raised: class (as sugar for constructor/prototype) uses Object.
> 
> But if you've read the thread this far, my objective is not to enforce one implementation approach or the other. It's to use @@toStringTag and anything like it so there's no observable difference between the two approaches. Classes should be able to do likewise.
> 
> Otherwise we have
> 
>  class C extends B {...}
> 
> and
> 
>  C.prototype instanceof Object
> 
> when the cowpath today wants
> 
>  C.prototype instanceof B

I'm not sure  what you are arguing for/against with the above point about instanceof.  

instanceof is it's own mechanism that is independent of toString,  [[Class]] tagging, or any concept that is used in section 15 of  ES<=5.1 when it is talking about instances of the various built-ins.  About the best you can do is create a table that compares all the various mechanism that do something like an "instance of" check against the actual built-in and look for the consistencies/inconsistencies. 

The current spec. language for class definitions would produce true for C.prototype instanceof B and false for C.prototype instanceof C.  But it would also answer true for C.prototype instanceof Object and B.prototype instanceof Object.

If there is an inconsistency here, it is that C.prototype claims to be instanceof B but in fact probably hasn't been initialized using the B constructor so it can't actually behave as a B instance.

Allen




More information about the es-discuss mailing list