I’m very confused with Mixins and Composition and Multiple Inheritance in JS, I think Object.assign

There are a few simple rules that make mixins safer:

  1. Mixins should not know about each other. (No implicit dependencies).
  2. Mixins should be small. Introduce as few new properties as possible.
  3. When composing, you can and should selectively inherit only the props you need, and rename props to avoid collisions.
  4. Prefer modules for code reuse whenever you can (which should be most of the time).
  5. Prefer functional programming for domain models and state management. Avoid shared mutable state.
  6. Prefer higher order functions and higher order components over inheritance of any kind (including mixins).

Mixins are immune to the fragile base class problem if you avoid creating inheritance hierarchies with them, and instead rely on feature-based composition.

People get into trouble with mixins when they try to treat them like classes. Don’t do that.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.