I've recently saw the concept of Mixin in javascript mainly through the article Real Mixins with javascript classes. And as I understand is a way to do multiple inheritance with abstract classes and it is more like a composition than an inheritance. I'm also reading about the concept composition over inheritance, as in the article Composition Over Inheritance. I'm aware that the discussion about inheritance and composition can be very long, but I've chosen to avoid inheritance as much as I can (at least for now).
So I would like to use Mixins as much as I can with ES6 and in most of examples I see three classes in action like class A extends MixinB(C)
. What if I want to extend only the class B? Would I do something like class A extends MixinB(Object)
? This might be an anti pattern as the Mozilla documentation states.
Note that I could do a direct inheritance like class A extends B
, but like this B
is not a Mixin anymore and I would need a different declaration of B
if I would like to use it as a Mixin.
Aucun commentaire:
Enregistrer un commentaire