new instantiation design alternatives

Claude Pache claude.pache at gmail.com
Fri Sep 19 01:59:45 PDT 2014


Le 19 sept. 2014 à 06:11, Kevin Smith <zenparsing at gmail.com> a écrit :

> 
> https://gist.github.com/zenparsing/5efa4459459b9f04d775
> 
> Cheers!
> 
> In the interest of the full dialectic, I encourage everyone tempted by new^ and all-degrees-of-freedom-including-hanging-yourself to look at this. It doesn't address some use-cases (constructor called differing from new'ed, notably), but perhaps that could be orthogonal via some MOP (if truly the hard/exceptional/native-legacy case).
> 
> That version almost, but not quite, holds together.  Another revision is forthcoming...
> 

I'm not sure that having two different ways to do subclassing is good. For instance, suppose that I have the following:

    class B extends Array {
        constructor(...args) extends new Array(...args) {
            // ....
        }
    }

I guess that, if someone try the following, it will not work as intended:

    class C extends B {
        constructor(...args) {
           /* A */
           super(...otherArgs)
          /* B */
        }
    }

What is confusing, is that it could work when extending other classes than `B`, with no obvious reason.
IIUC, they could make working by writing something resembling to:

    class C extends B {
        static creator(...args) {
            /* A */
            return otherArgs
        }
        constructor(...args) extends new super(... C. creator(...args)) {
            /* B */
        }
    }

Here, the `creator` static methods joined to the extends clause of constructor play the role of @@create, and are called in bottom-up order, whereas the constructor methods are called in top-down order. I've thought yesterday of such a design where the constructor is split in two optional parts like that. Well finally, it would be simply equivalent to:

    class C extends B {
        constructor(...args) {
            /* A, using new^ */
            this = new super(...otherArgs)
            /* B, using this */
        }
    }


—Claude

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140919/fb348629/attachment.html>


More information about the es-discuss mailing list