node.class
v1.1.4
Published
A port of John Resig Class Implementation
Downloads
553
Readme
node.class
A port of John Resig Simple JavaScript Inheritance on node.js plus multiple inheritance
.
Requires
Checkout package.json
for dependencies.
Installation
Install through npm
npm install node.class
Usage
Require the module before using
var Class = require( 'node.class' );
Basic
var Person = Class.extend({
// constructor
init : function ( name, height ){
this.name = name;
this.height = height;
},
show_name : function (){
return this.name;
},
show_height : function (){
return this.height;
}
});
var ben = new Person( 'ben', '176' );
console.log( ben.height()); // 176
Multiple inheritance
var car = {
init : function ( name ){
this.name = name;
},
run : function (){
// ...
},
stop : function (){
// ...
}
};
var sports_car = {
turbo : function (){
// ...
}
};
var Porsche = Class.extend( car, sports_car );
var nine11 = new Porsche( '911' );
nine11.turbo();