The documentation explain how to extend a class
class Zebra extends Animal
...
But how do I extend multiple classes? The following does not work
class Sidebar extends Controller, EventEmitter
...
But I wish it did. The JavaScript behind this is more than able to extend any number of classes using the __extend function, but is there a way to do it in coffee-script?
Guess I’ll just answer my own question. The way I ended up handling this is extending all my classes from a class I call “SuperClass” (the name doesn’t matter). From that class I can extend any number of classes. Anyway the class looks like this
Pretty much just stole it from Spine. An example of a class extended from SuperClass:
Notice that to call the inherited class’ constructor the class function is called with
@/thisas context. I haven’t needed to extend class functions yet, but I imagine it’s very similar to calling the parent constructor:Please edit this post if I’m wrong. Also please excuse my lack of class inheritance terminology – I’m no expert
Update: One could also define a constructor for SuperClass that automatically called the constructor for all included classes on instantiation. That way you’d just need to call
super()from the subclass. I haven’t bothered with that though