Re: How to specify an object that can be mutable or immutable

On 9/26/13 5:33 AM, Cameron McCormack wrote:
> Would it be too fancy to try to use inheritance to relate DOMRect and
> DOMRectReadOnly?  Web IDL already has this syntax:
>
>    interface DOMRectReadOnly {
>      readonly attribute double x;
>      ...;
>    };
>
>    interface DOMRect : DOMRectReadOnly {
>      inherit attribute double x;
>      ...
>    };
>
> which basically means to have the same behaviour for
> DOMRect.prototype.x's getter as DOMRectReadOnly.prototype.x's.

The big drawback from my pov is that this setup means you can't 
interpose your own getter on DOMRectReadOnly and have DOMRect pick it 
up....  I really wish ES allowed defining the inheritance directly in 
the language.  As it is, maybe "inherit" should end up forwarding to the 
canonical parent proto's getter, instead of calling the same internal impl?

It's hard to say which is more "idiomatic"; both are viable 
implementation strategies.

-Boris

Received on Thursday, 26 September 2013 15:27:24 UTC