0.1.1 • Published 9 years ago

weak-inherit v0.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

node-weak-inherit Travis-CI.org Build Status Coveralls.io Coverage Rating

Weakly inherit a class/function's prototype on any object

This point of this module is to allow the extension of a class and its method on top of objects that are not necessarily classes themselves.

This is useful for API builders in particular which need to "extend" a class on to a function that is still callable itself.

Example

var weakInherit = require('weak-inherit');
var EventEmitter = require('events').EventEmitter;

var fn = function (name) {
	console.log('Hello,', name);
};

// anything we pass to `generator` will extend EventEmitter
var generator = weakInherit(EventEmitter);

var obj = generator(fn);

fn('Qix'); //-> Hello, Qix

fn.on('test', function () {
	console.log('Hi!');
});

fn.emit('test'); //-> Hi!

License

Licensed under the MIT License. You can find a copy of it in LICENSE.