Thanks to visit codestin.com
Credit goes to github.com

Skip to content

yiwn/inherit

Repository files navigation

inherit

Inherit functionality and setup prototype chain from subclasses.

Installation

Using component

$ component install yiwn/inherit

Using npm for browserify

$ npm install yiwn-inherit

Usage

Example:

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

function Parent(b){
    this.a = 'Aaa!',
    this.b = b;
    return this;
}

Parent.extend = inherit.bind(null, Parent);

// 
var Child = Parent.extend({
        print: function(){
            console.log(this.a, this.b);
        }
    });

var child = new Child('Boo!');

child.print(); // -> 'Aaa!', 'Boo!'

Supports replacement of constructor function as third argument.

var Child = Parent.extend({
        print: function() {
            console.log(this.a, this.b)
        }
    }, init);

function init(b) {
    this.b = b + '!!!';
    return this;
}

var child = new Child('Boo!');

child.print(); // -> undefined, 'Boo!!!!'

Test

Run tests with mocha

$ make test

Origins

Script replicates functionality of Backbone's .extend, extracted from Koboldmaki.

License

The MIT License

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •