Skip to content

ThinkingStudio/inheritancejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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"}

About

a simple javascript inheritance utility

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published