0.1.0 • Published 10 years ago

yiwn-inherit v0.1.0

Weekly downloads
8
License
-
Repository
-
Last release
10 years ago

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

0.1.0

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.0.3

10 years ago