coop

Co-operative multiple inheritance for JavaScript

Co-Op provides Pythonic cooperative multiple inheritance to Javascript and Node.js.

Installation

npm install coop

Usage

Creating a class is similar to Mootools:

var Class = require('coop').Class;
var MyClass = new Class({
  initializefunction(me) {
    this.me = me;
  }
});

...is a little different from Mootools. But orders of magnitude more powerful.

var MySubClass = new Class([MyClass, MyOtherClass], {
  initializefunction (me) {
    this.super_initialize(MySubClass, arguments);
  }
})

Make your own subclass of Class, and override new, just like you do in Python:

var MyMetaClass = new Class([Class], {
  __new__function (klass) {
    var instance = this.super___new__(MyMetaClass, arguments);
 
    registerMyClass( instance );
 
    return instance;
  }
})
 
var MyClass = new MyMetaClass({
  initializefunction () { /* ... */ }
})