Declan de Wet
Jul 28, 2017 · 1 min read

I think this article is missing a more detailed section on class mixins:

const Barking = base => class extends base {
bark () {
console.log('woof!')
}
}
const Sitting = base => class extends base {
sit () {
console.log(`${this.name} sits ${this.attribute}ly`)
}
}
const Meowing = base => class extends base {
meow () {
console.log('meow!')
}
}
class Animal {
constructor (name) {
this.name = name
}
}
class Dog extends Barking(Sitting(Animal)) {
constructor (name) {
super(name)
this.attribute = 'loyal'
}
}
class Cat extends Meowing(Sitting(Animal)) {
constructor (name) {
super(name)
this.attribute = 'luxurious'
}
}
const fido = new Dog('Fido')
fido.bark() // woof!
fido.sit() // Fido sits loyally
const mittens = new Cat('Mittens')
mittens.meow() // meow!
mittens.sit() // Mittens sits luxuriously

    Declan de Wet

    Written by

    Founder of @obdynamics

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade