Whilst on the topic of object literal extensions, did we make any progress on supporting what allen calls exemplars<https://mail.mozilla.org/pipermail/es-discuss/2011-October/017369.html> ?
let Employee = Person <| { constructor(name, title) { super(name); this.title = title; }, describe() { return super.describe(this) + " (" + this.title + ")"; } }; On Sat, Oct 29, 2011 at 4:23 AM, Axel Rauschmayer <a...@rauschma.de> wrote: > http://brendaneich.com/2011/10/jsconf-eu/ > > I’d be sad not to have class literals in JavaScript. However, with the new > object literal extensions, things are still much better than in ES5. > Compare: The ES5 version is clumsy. > > // Super > function Person(name) { > this.name = name; > } > Person.prototype.describe = function() { > return "Person called "+this.name; > }; > > // Sub > function Employee(name, title) { > Person.call(this, name); > this.title = title; > } > Employee.prototype = Object.create(Person.prototype); > Employee.prototype.constructor = Employee; > Employee.prototype.describe = function() { > return Person.prototype.describe.call(this)+" ("+this.title+")"; > }; > > The ES.next version is quite nice: > > // Super > function Person(name) { > this.name = name; > } > Person.prototype .= { > describe() { > return "Person called "+this.name; > } > } > > // Sub > Person <| function Employee(name, title) { > super(name); > this.title = title; > } > Employee.prototype .= { > describe() { > return super.describe(this)+" ("+this.title+")"; > } > }; > > This is not bad at all, quite teachable! Having a single construct instead > of piecing things together via multiple assignments might be a problem in > some cases. Then you could use the latest incarnation of Allen’s class > pattern: > > Person <| function Employee(name, title) { > super(name); > this.title = title; > }.={ > prototype.={ > describe() { > return super.describe(this)+" ("+this.title+")"; > } > } > // “class” variables go here > } > > [I’m using the destructive version of the extension operator, as shown in > Brendan’s blog post] > > -- > Dr. Axel Rauschmayer > a...@rauschma.de > > home: rauschma.de > twitter: twitter.com/rauschma > blog: 2ality.com > > > > _______________________________________________ > es-discuss mailing list > es-discuss@mozilla.org > https://mail.mozilla.org/listinfo/es-discuss >
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss