0.0.2 • Published 11 years ago

define-class v0.0.2

Weekly downloads
5
License
-
Repository
github
Last release
11 years ago

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

11 years ago

0.0.1

11 years ago