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

Brendan Eich brendan at mozilla.com
Mon Oct 1 13:04:47 PDT 2012


Rick Waldron wrote:
> On Mon, Oct 1, 2012 at 3:21 PM, Brendan Eich <brendan at mozilla.com 
> <mailto:brendan at mozilla.com>> wrote:
>
>     Andreas Rossberg wrote:
>
>         Er, from my reading that's clearly not what the Wiki says for
>         WeakMap. And it also is not what V8 implements, for either
>         WeakMap or Map.
>
>
>     Sorry, I was relying on Rick's testimony that the answers were 1)
>     yes, 2) no.
>
>
>
> Yes, when I first considered the topic, it seemed to make some kind of 
> sense (based on a desire for consistency), but I also don't believe 
> that should be the case now—I even noted that I had always 
> subjectively viewed resulting behaviours as "strange".

Oops, then I really misread one of your messages -- I thought you had 
tested in V8.

> I'm not sure I've ever encountered code in the wild that made any 
> intentional use of built-ins Foo.prototype-as-firstborn - can anyone 
> on the list point to some compelling use cases?

If it doesn't matter, we could make all the built-ins' 
constructor.prototype objects be instances of Object (except for the 
Error subclasses!).

That would be nice. Then we'd have

   class C extends B {}
   assert(C.prototype instanceof B)

and per Allen's nifty trick of avoiding class-side inheritance from 
Object (which made Dave hear angels sing):

   class C {}
   assert(C.prototype instanceof Object)

/be


More information about the es-discuss mailing list