🔥 Burn Fat Fast. Discover How! 💪

5. When is prototypal inheritance an appropriate choice? Ther | Coding interview preparation

5. When is prototypal inheritance an appropriate choice?

There is more than one type of prototypal inheritance:

- Delegation (i.e., the prototype chain).
- Concatenative (i.e. mixins, Object.assign()).
- Functional (Not to be confused with functional programming. A function used to create a closure for private state/encapsulation).

Each type of prototypal inheritance has its own set of use-cases, but all of them are equally useful in their ability to enable composition, which creates has-a or uses-a or can-do relationships as opposed to the is-a relationship created with class inheritance.

Good to hear:

In situations where modules or functional programming don’t provide an obvious solution.
When you need to compose objects from multiple sources.
Any time you need inheritance.

Red flags:

No knowledge of when to use prototypes.
No awareness of mixins or Object.assign().

#javascript #js