inheritancejs

0.0.2 • Public • Published

inheritancejs

Simple utility for implementing javascript inheritance

Install

npm install inheritancejs

Usage

var extend = require('inheritancejs');
 
function Base(name, age){
    this.name = name;
    this.age = age;
}
Base.prototype.state = function() {
    return {
        name: this.name,
        age: this.age
    };
};
Base.prototype.log = function() {
    console.log(this.state());
}
 
function ExtendConstructor(name, age, sex){
    this.sex = sex;
}
 
 
function Extend = extend(Base, ExtendConstructor);
Extend.prototype.state = function() {
    var p = this.parent.state.call(this);
    p['sex'] = this.sex;
    return p;
}
 
var myObject = new Extend('a', 10, 'm');
myObject.log(); // output {name: "a", age: 10, sex: "m"}
 
 

Readme

Keywords

Package Sidebar

Install

npm i inheritancejs

Weekly Downloads

0

Version

0.0.2

License

none

Last publish

Collaborators

  • greenlaw110