Grokking Advanced JavaScript
Vote

0% completed

​

Mixins

A class can extend only one other class. ElectricCar already extends Car, so when an electric car also needs the charging behavior that a phone has, extends cannot supply it. JavaScript has no multiple inheritance: there is no syntax such as class ElectricCar extends Car, Chargeable.

The usual answer is to copy the shared methods onto a class instead of inheriting them. An object that holds a group of methods meant to be copied into other classes is called a mixin, and copying them in is called mixing in

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content