Simple and efficient class inheritance based on John Resig's code ("Simple JavaScript Inheritance" and "Simple Class Instantiation").
Written for being used with node.js.
Installation
npm install class.js
Example
var Class = require('class.js');
var A = Class({
init: function(x) {
this.x = x;
},
f: function() {
this.x += 2;
}
});
var a = new A(7);
var a2 = A(7);
var B = A.extend({
init: function(x) {
this._parent(x / 2);
},
f: function() {
this._parent();
this.x += 3;
},
g: function(a, b) {
}
});
var X = Class({ });
var Y = X.extend({ });
var b = new B(11);
var x = new X();
var y = new Y();
a instanceof A;
b instanceof B;
b instanceof A;
x instanceof X;
y instanceof Y;
y instanceof X;
a instanceof B;
x instanceof Y;
x instanceof A;
b instanceof Y;
var C = B.extend({
init: function() { }
x: function() {
A.prototype.f.call(this);
}
});
Useful JsDoc for your IDE
var A = Class( {
init: function() { }
f: function() { }
});
var B = A.extend( {
init: function() { }
g: function() { }
});
About