Facebook Pixel

Can JavaScript do multiple inheritance?

Not directly (each object has one prototype). But you can simulate it with composition: Object.assign(obj, mixin1, mixin2). This copies properties from multiple sources. Mixins are the JS way to achieve multiple inheritance-like behavior.

Verify This Answer

Cross-check this information using these trusted sources:

More FAQs in Prototypal vs Classical Inheritance

Classical: classes inherit from classes (static, strict, compile-time). Prototypal: objects inherit from objects (dynamic, flexible, runtime). JS uses prototypal. ES6 classes are syntactic sugar over prototypes.

Yes. Use Object.setPrototypeOf(obj, newProto). This is possible because JS uses prototypal inheritance (dynamic). In classical inheritance, the hierarchy is fixed at compile time.

Composition is often preferred. Instead of deep inheritance chains, mix objects: Object.assign(bird, canFly, canSwim). This is more flexible and avoids the problems of deep inheritance (fragile base class, tight coupling).

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.