0.1.1 • Published 9 years ago

inherits-js v0.1.1

Weekly downloads
202
License
MIT
Repository
github
Last release
9 years ago

inherits.js

Backbone inspired standalone inheritance function.

Inherits.js is a yet another tool for inheritance, inspired by Backbone's extend method. It creates Child constructor function with prototype chained from parent and with extended parent's static properties.

Getting started

Inherits.js is compatible in any module environment (AMD, CJS) or just as global function in browser, if nor defined.

You could install it via npm, or download directly from dist folder.

Interface

inherits(parent, [prototypeProperties , staticProperties]);

Where:

  • parent is a parent Function constructor;
  • prototypeProperties is an Object with child prototype;
  • staticProperties is an Object with static properties and methods for child constructor.

Usage

var MyParentClass,
    MyChildClass,
    MyAnotherClass;

// First usage case
// ----------------

MyParentClass = function() {
  // ...
}

MyParentClass.prototype = {
    method: function() {
        //
    }
};

MyParentClass.extend = function(protoProps, staticProps) {
    return inherits(this, protoProps, staticProps);
};

MyChildClass = MyParentClass.extend({
    method: function() {
        //
    }
});

// Second usage case
// -----------------

MyAnotherClass = inherits(MyParentClass, {
    constructor: function() {
        //
    },

    method: function() {
        //
    }
}, {
    STATIC: 1
});