active-class

0.0.1 • Public • Published

active-class

Build Status Coverage Status

Define your Class with JavaScript.

Installation

$ npm install -g bower
$ bower install active-class

Or just use the bundled version in the dist directory.

Usage

Simple Inheritane

To create a new class, use the following syntax:

var MyClass = Class(prototype);
var Foo = Class({
  _constructor: function (name) {
    this.name = name;
  },
  say: function (prefix) {
    return prefix + ' ' + this.name;
  }
});

var foo = new Foo('foo');
foo.say('hello'); // hello foo

Multiple Inheritance

To create a new class with multiple inheritance, use the following syntax:

var MyClass = Class(Class1, Class2, prototype);

Note that instanceof reflection will only reveal Class1 as superclass.

var Parent = Class({
  _constructor: function (name) {
    this.name = name;
  },
  say: function (prefix) {
    return prefix + ' ' + this.name;
  }
});
var Teacher = Class({
  _constructor: function (name) {
    this.name = name;
  },
  teach: function () {
    return 'Teach ' + this.name;
  }
});
var Child = Class(Parent, Teacher, {
  _constructor: function (name) {
    this.name = name;
  },
  getName: function () {
    return this.name;
  },
  setName: function (name) {
    this.name = name;
  },
  say: function (prefix, postfix) {
    return Parent.prototype.say.call(this, prefix) + ' ' + postfix;
  }
});

Documentation

Refer to doc directory, and it's generated with docco. You could check the online doc from here.

Build

$ grunt

Test

$ npm test

TODO

  • Add Getter & Setter support
  • Add static method inheritance support
  • ...

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i active-class

Weekly Downloads

1

Version

0.0.1

License

MIT

Last publish

Collaborators

  • starandtina