On Tue, Jun 11, 2013 at 5:33 PM, Brendan Eich <[email protected]> wrote:
> Brian Di Palma wrote: > >> Sorry for the OT message. >> >> On Tue, Jun 11, 2013 at 6:22 PM, Andrea Giammarchi >> <[email protected]> wrote: >> >>> We don't have interfaces ... I know, we could have mixins though, >>> compatible >>> with @@things too. >>> >>> >> The concepts of Mixins has cropped up before in discussions and is >> used in current JS code ( EventEmitter ). >> I was wondering if it was possible to codify it in ES6 or is there >> simply no bandwidth/time for that? >> >> class MyClass extends MySuper mixin EventEmitter, Iterable {} >> > What would this syntax do that couldn't be done better by libraries? > Remember that extends' RHS is an expression. Don't wanna go off-topic of course, but: the the fact that RHS is an expression might you think Object.mixin(...) can be used there: class Foo extends Object.mixin(...) The problem with it as I mentioned (and which was successfully and unfortunately ignored ;)), it accepts only two arguments instead of variant to mix several objects. But even it Object.mixin(...) could accept several arguments, we still can't extend a class with another class _and_ a set of mixins. class Bar extends Object.mixin(Foo, M1, M2...), where Foo is a class and Ms are mixin. To do this you'll need to either express classes's implementation details (i.e. to break classes abstraction): class Bar extends Object.mixin(Foo.prototype, M1...); Or, yeah, to provide a library method: class Bar extends classWithMixins(Foo, M1, M2...); (the later example is actually a real implementation we use in local projects currently). Another issue with a library method -- it just looks immature for a mature language. From this viewpoint: class Bar extends Foo { use M1, M2; } looks better and mature as all normal OOP langs with mixins/traits. IMHO. But as long as ES6 spec is already (almost) stable, I agree it can be taken to something ES7-ish. Dmitry
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

