double-latte
v1.0.1
Published
Multiple inheritance for CoffeeScript
Downloads
5
Readme
Double Latte
Python-like MRO based multiple inheritance for CoffeeScript.
Works with all javascript engines supported by CoffeeScript.
Example
{multiple, isinstance, issubclass} = require "double-latte"
class A
constructor: ->
console.log "A"
class B extends A
constructor: ->
console.log "B"
super
class C extends A
constructor: ->
console.log "C"
super
class D extends multiple B, C
constructor: ->
console.log "D"
super
d = new D # will print D; B; C; A;
isinstance d, B # true
Install
npm install double-latte
FAQ
Q: Can I use this with <insert favorite compile-to-javascript language here> *
A: Probably not. This relies on the cls.__super__
property that CoffeeScript uses to figure out what parent to call. If your compiler does that, then maybe.
Q: How fast is this?
A: Fast enough ( Guido for president! ). If you're that worried about performance then you should probably code in javascript directly.
Q: What's the deal with isinstance
?
A: For technical reasons, the instanceof
operator doesn't work with classes that have multiple parents. The isinstance
and issubclass
are provided to work around this fact.