yiwn-inherit
v0.1.0
Published
Extend functionality and setup prototype chain from subclasses.
Downloads
2
Readme
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