Mark S. Miller wrote: > <inheritance> > > > Point as a non-final non-abstract root/mixin class where toString is a > final method: > > function PointMixin(self, x, y) { > Object.defineProperties(self, { > toString: {value: Object.freeze(function() ('<' + self.getX() > + ',' + self.getY() + '>'))}, > enumerable: true}, > getX: {value: Object.freeze(function() x), > enumerable: true, flexible: true}, > getY: {value: Object.freeze(function() y), > enumerable: true, flexible: true} > }); > } > function Point(x, y) { > const self = Object.create(Point.prototype); // only for instanceof > PointMixin(self, x, y); > return Object.freeze(self); > } > Object.freeze(PointMixin); > Object.freeze(Point.prototype); > Object.freeze(Point); > > > WobblyPoint as a non-abstract non-final subclass: > > function WobblyPointMixin(self, wobble) { > const super = Object.snapshot(self); // a snapshot is a frozen copy > Object.defineProperties(self, { > getX: {value: function() (super.getX() + Math.random()*wobble), > enumerable: true, flexible: true} > }); > } > function WobblyPoint(x, y, wobble) { > const self = Object.create(WobblyPoint.prototype); // only for instanceof > PointMixin(self, x, y); > WobblyPointMixin(self, wobble); > return Object.freeze(self); > } > Object.freeze(WobblyPointMixin); > WobblyPoint.prototype = Object.create(Point.prototype, { > constructor: {value: WobblyPoint} > }, true); > Object.freeze(WobblyPoint); > > > This gets self-overriding a super-binding correct under single > inheritance and even under linearized multiple inheritance. > > > </inheritance> >
That code is ugly. -dean _______________________________________________ Es-discuss mailing list Es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss