constructor, super, and data members issue

Allen Wirfs-Brock allen at wirfs-brock.com
Sat Aug 25 15:56:33 UTC 2018


Base cases that take dependencies upon information potentially supplied by subclass have to be intentionally design to make that work. And the chosen design should be document as part of its subclassing contract.  For the example shown there  is there is a long known pattern that can be used:

  class Base {
        constructor() {
             ....
             .. idAttribute ..
             ....
        }
        idAttribute = this.__idInitializer();  //initial id value may be supplied by a subclass
        __idInitialier() {
            // override this method if you want your subclass to provide an alternative initial idAttribute value
            // the subclass override method should not be dependent upon subclass fields.
            return ‘id’;
       ’}
    }

   class Derived extends Base {
        constructor() {
             super();
             ....
        }
        __idInitializer() {return ‘_id’}
   }

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


More information about the es-discuss mailing list