coop
v0.4.0
Published
Co-operative multiple inheritance for JavaScript
Downloads
32
Maintainers
Readme
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({
initialize: function(me) {
this.me = me;
}
});
Inheritance
...is a little different from Mootools. But orders of magnitude more powerful.
var MySubClass = new Class([MyClass, MyOtherClass], {
initialize: function (me) {
this.super_initialize(MySubClass, arguments);
}
})
Metaclasses
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({
initialize: function () { /* ... */ }
})