0.0.5 • Published 13 years ago
node-binder v0.0.5
node-binder
Mixin class for managing bindings in Node.js
API
bind(emitter, event, fn , context)
Binds fn to the event of emitter and keeps track of bindings for easy destruction.
Arguments
emitter- Any object that inheriets fromEventEmitter.event- Name of the event onemitterto which thefnwill be bound.fn- Function handler for theevent.context- Optional. Context with which to execute thefn.
destroy()
Unbinds all events previously bound using bind.
Example
function SomeStreamingClass() {}
SomeStreamClass.prototype.onData = function(chunk) {
/* Do some cool stuff… */
}
var Binder = require("node-binder");
var binder = new Binder();
var someStream = new SomeStreamClass();
binder.bind(someStream, "data", someStream.onData, someStream);
/* Later on when you no longer need someStream… */
binder.destroy();