weak-inherit
v0.1.1
Published
Weakly inherit a class - no prototypes involved
Downloads
13
Maintainers
Readme
node-weak-inherit
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.