Extending multiple classes using abstract classes

Abstract classes could dictate the existence of certain properties in a child class.

I'll use the generic duck example.

abstract class Flying {
  define() {
    return ["fly"] // Flying.prorotype.fly exists
  }
}

abstract class Swimming {
  define() {
    return ["swim"] // Swmming.prorotype.swim exists
  }
}

Now a duck should be able to extend both these classes.

class Duck extends Flying, Swimming { // or maybe implements
  fly() {
    // flies
  }
  swim() {
    // swims
  }
}

https://github.com/tc39/proposal-first-class-protocols

1 Like

Thanks!