extends null

Mark S. Miller erights at google.com
Sun Feb 15 11:12:06 PST 2015


On Sun, Feb 15, 2015 at 11:01 AM, Kevin Smith <zenparsing at gmail.com> wrote:

>
>> Interesting. I have never seen this pattern and don’t see what it could
>> be good for. Thus, a dynamic error at class definition time sounds good to
>> me.
>>
>
> The purpose would be defining a class whose instances don't have
> Object.prototype on their prototype chain.  If "extends null" doesn't work,
> then I think you'd have to do something like this to achieve the same?
>
>     function NullBase() {}
>     NullBase.prototype = Object.create(null);
>
>     class C extends NullBase {}
>
>
That still wouldn't work at runtime because of the super semantics of C as
a derived class. Instead


class C {....}

C.prototype.__proto__ = null;

Yes, it is ugly, but it is an odd case, so still obeys Kay's dictum:


"Simple things should be simple. Complex things should be possible"
    --Alan Kay





-- 
    Cheers,
    --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150215/c5fffd60/attachment.html>


More information about the es-discuss mailing list