This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

define-class

0.0.2 • Public • Published

define-class

A Simple JavaScript Inheritance Module

Usage

Define Classes

var DefineClass = require('define-class');
 
// Person Class
var Person = DefineClass({
  //put all static 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 static 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() );

Readme

Keywords

none

Package Sidebar

Install

npm i define-class

Weekly Downloads

0

Version

0.0.2

License

PUBLIC DOMAIN (UNLICENSED)

Last publish

Collaborators

  • luizbills