Skip to content

zhangaz1/inherit-helper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

inherit-helper

simple inherit

Example

var helper = require('inherit-helper');

var Parent = helper.create(
    function(name) {
        this.name = name;
    },
    function(proto) {
        proto.getName = function() {
            return this.name;
        }
    }
);

var Child = Parent.extend(
    function(name, age) {
        this.age = age;
    },
    function(proto) {
        proto.getAge = function() {
            return this.age;
        }
    }
);

var MyClass = helper.extend(
    function() {
        // init;
    },
    Object,
    function(proto) {
        // set protos;
    }
);

Installation

npm install inherit-helper

Usage

Basic usage that like this:

var p1 = Parent(name); // or: new Parent(name);

assert.equal(p1.name, name);
assert.equal(p1.getName(), name);

assert.equal(typeof(Child.extend), 'function');

var c1 = new Child(name, age);
assert.equal(c1.name, name);
assert.equal(c1.getName(), name);
assert.equal(c1.age, age);
assert.equal(c1.getAge(), age);

Parent.prototype.getSomething = function() {
    return somthing;
};

assert.equal(p1.getSomething(), somthing);
assert.equal(c1.getSomething(), somthing);

License

MIT. © 2012 Aseem Kishore.

About

inherit helper

Resources

License

Stars

Watchers

Forks

Packages

No packages published