node.class

A port of John Resig Class Implementation

node.class

A port of John Resig Simple JavaScript Inheritance on node.js plus multiple inheritance.

Checkout package.json for dependencies.

Install through npm

npm install node.class

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();