tc39 / proposal-mixins

A template for ECMAScript proposals
MIT License
61 stars 2 forks source link

Should mixins be inheritance-based? #8

Open zenparsing opened 5 years ago

zenparsing commented 5 years ago

The inheritance-based approach to mixins has some odd side-effects:

Usually I want to use mixins to simply "fill out" a bunch of features on the concrete class. In other words, I want to copy properties from the mixin source to the mixin target.

What would the tradeoffs be for an alternate design where class C with ... copies properties from the source, rather than building up an inheritance chain?

Thanks!

canonic-epicure commented 4 years ago

I think this point

It's a little unclear how multiple mixins ought to work

Is exactly the opposite with inheritance-based mixins (I'm strong proponent of those)

It is very clear, how multiple inheritance-based mixins combines together. And it is very unclear how they combine for copying-based mixins. Here's why:

Inheritance-based mixins, as follows from their name, just performs inheritance. This is a simple, intuitive concept, everybody understands very well. If you combine several mixins - thats just long inheritance chain, thats all. Again, the intuition, developed from the years of work with single-class inheritance answers all questions.

For copying-based mixins there's no such intuition to re-use. You need to write some specification that will define all edge cases: