Skip to content
A Simple JavaScript Inheritance Module
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
src
test
LICENSE
README.md
package.json

README.md

define-class

A Simple JavaScript Inheritance Module

Usage

Define Classes

var DefineClass = require('define-class');

// Person Class
var Person = DefineClass({
  // put all instance method/props here

  // constructor
  init: function(name) {
    this.name = name;
  },

  dance: function() {
    return this.name + " says: I'm dancing";
  }
}, {
  // put all static method/props here
  someStaticMethod: function() {
    return 'called a static method';
  }
});

var person = new Person('Phil');
console.log(person.dance());

Extends a Class

var DefineClass = require('define-class');

// Ninja Class
var Ninja = DefineClass(Person /*parent class*/, {
  // put all instance method/props here

  // constructor
  init: function(name) {
    //call the method of parent class 
    this._super(name);
  },

  dance: function() {
    return this._super() + ", but I'm a ninja!";
  }
}, {
  // put all static method/props here
  ninjaStaticMethod: function() {
    return 'called a static method';
  }
});
// note: static methods don't are extended

var ninja = new Ninja('Jack');
console.log( ninja.dance() );
Something went wrong with that request. Please try again.