EventEmitter Class for the browser based on NodeJS EventEmitter.
$ component install pazguille/jvent
See: https://github.com/component/component
Also, you can use the standalone version without components.
<script src="../dist/jvent.js"></script>First, requires Jvent:
var Jvent = require('jvent');Creates a new instance:
var emitter = new Jvent();Now, defines a listener:
function listener(arg1, arg2) {
alert(arg1 + ' '+ arg2);
})Then, adds a new event live with a listener:
emitter.on('live', listener);Emitsthe event with some data:
emitter.emit('live', 'param1', 'param2');Adds a listener to the collection for a specified event.
event- The name of the event you want to add.listener- Listener you want to add from given event.
emitter.on('live', listener);Adds a one time listener to the collection for a specified event. It will execute only once.
event- The name of the event.listener- Listener you want to add from the given event.
emitter.once('live', listener);Removes a listener from the collection for a specified event.
event- The name of the event.listener- Listener you want to remove from the given event.
emitter.off('live', listener);Removes all listeners from the collection for a specified event.
event- The name of the event you want to remove.
emitter.removeAllListeners('live');Returns all listeners from the collection for a specified event.
event- The name of the event.
emitter.listeners('live');Execute each of the listeners collection in order with the given parameters.
All emitters emit the event newListener when new listeners are added.
event- The name of the event you want to emit.
emitter.emit('live', 'data1', 'data2');## Maintained by
- Guille Paz (Front-end developer | Web standards lover)
- E-mail: guille87paz@gmail.com
- Twitter: @pazguille
- Web: http://pazguille.me
Licensed under the MIT license.
Copyright (c) 2012 @pazguille.

