- From: Rick Waldron <waldron.rick@gmail.com>
- Date: Thu, 26 Sep 2013 17:22:18 -0400
- To: Boris Zbarsky <bzbarsky@mit.edu>
- Cc: "public-script-coord@w3.org" <public-script-coord@w3.org>
- Message-ID: <CAHfnhfovTLM-L=Vmyqa2d1-wDHtQaGNbKwnwTSCztXVdB_h8xg@mail.gmail.com>
On Thu, Sep 26, 2013 at 11:13 AM, Boris Zbarsky <bzbarsky@mit.edu> wrote:
> On 9/26/13 8:15 AM, Domenic Denicola wrote:
>
>> Can somebody spell out how this proposed inheritance hierarchy works in
>> actual ECMAScript, not WebIDL?
>>
>
> In ES5 (because I'm not up to date on ES6 class syntax), and ignoring the
> .constructor hookups and whatnot:
>
> function DOMRectReadonly() {
> // Some stuff here
> }
> DOMRectReadonly.prototype = Object.create(Object.**prototype,
> {
> left: {
> get: function left() {
> // stuff here
> }
> }
> // more members
> };
>
Or just:
DOMRectReadonly.prototype = {
get left() {
return 0;
}
};
>
>
> function DOMRect() {
> // Some stuff here
> }
> DOMRect.__proto__ = DOMRectReadonly;
> DOMRectReadonly.prototype = Object.create(DOMRectReadonly.**prototype,
> {
> left: {
> get: function left() {
> // stuff here, which is a copy-paste of the getter on
> // DOMRectReadonly.prototype, or an invocation of the
> // canonical version of that getter.
> },
> set: function set_left(arg) {
> // stuff here
> }
> }
> // more members
> }
>
> I _think_ in terms of ES6 classes this would be:
>
> class DOMRectReadonly {
> get left() {
> // stuff here
> }
> }
>
> class DOMRect extends DOMRectReadonly {
> get left() {
> // stuff here
> }
> set left(arg) {
> // stuff here
> }
> }
>
Just to confirm, this is correct and produces equivalent class/constructor
objects as are created in your ES5 example.
Rick
Received on Thursday, 26 September 2013 21:23:04 UTC