node-binder
v0.0.5
Published
Mixin class for managing bindings in Node.js
Downloads
1
Readme
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 onemitter
to which thefn
will 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();