(Yet another) Event emitter for Node, Browser globals and AMD
Browser globals, AMD and Node Events
bane is a small event emitter library that works in browsers (including old
and rowdy ones, like IE6) and Node. It will define itself as an AMD module if
you want it to (i.e. if there's a
define function available).
bane is not entirely API compatible with Node's event emitter, but it does
provide the iconic
npm install./node_modules/buster/bin/buster-test --node./node_modules/buster/bin/buster-server./node_modules/buster/bin/buster-test --browser
Create a new event emitter. If an object is passed, it will be modified by adding the event emitter methods (see below).
listener function to be called when the emitter emits the
event (which is a string).
listener function as a "supervisor". It will be called for
any event emitted from the emitter.
Remove a previously registered
listener function for the specified
(which is a string). If the function has not previously been registered, it is
Remove a previously registered "supervisor"
listener function. If the
function has not previously been registered, it is silently ignored.
Remove all previously registered
listener functions for the specified
event (which is a string). If no functions have previously been registered,
it is silently ignored.
Remove all previously registered listeners on the object, both regular listeners, supervisor listeners, and errbacks. If no functions have previously been registrered, it is silently ignored.
listener function for the given
event (which is a string)
only once. After the first event has been emitted, the listener is removed.
Register all methods on
object as listeners for the event named as the
method name. Convenient way to bind many event listeners in one go:
var listener =console.log"Started!";console.log"Ended";;emitterbindlistener;
The above example will bind
listener.start to the
"start" event and vice
end. Note that property names can be quoted to bind to any kind of
event name (e.g.
Binds methods on
object to corresponding events (see
above), but instead of binding all methods on the object, only binds the
events listed in the provided
listener function as an "errback". It will be called with the
error for any error thrown when listeners are
event (which is a string) with optional data. Will cause all
registered listeners for the named event to be called. If additional arguments
are provided, the listeners will be called with them.
Two-clause BSD-license, see LICENSE