// initialize an event emittervar ee = ;// create a callback functionvarconsole.log'The foo event was emitted.';;// register the callbackeeon'foo' fooCallback;// emit the eventeeemit'foo'; // #=> "The foo event was emitted."
Detailed API documentation will be coming soon.
How to use in a browser:
How to use in node:
var EventEmitter = require('./lib/eventful.js');
eeon'foo'console.log'The foo event was emitted.';on'bar'console.log'The bar event was emitted.';emit'foo'emit'bar';;
varconsole.log'The foo event was emitted.';;varconsole.log'The bar event was emitted.';;// register both callbackseeon'foo' fooCallbackon'bar' barCallback;// you can remove a specific callbackeeoff'foo' fooCallback;// or you can remove all callbacks for the foo eventeeoff'foo';// nothing happens any more with the foo eventeeemit'foo';// the bar callback is still registeredeeemit'bar'; // #=> "The bar event was emitted."// finally, you can also remove all callbacks like thiseeoff;// nothing happens with any eventeeemit'bar';
eeon'foo'console.log'I was called with ' + arg + '.';;eeemit'foo' 'bar'; // #=> "I was called with bar."
// register your callbackseeon'fubar' fooCallbackon'fubar' barCallback;// get the list of registered callbacksvar callbacks = eeon'fubar';// check its contentsconsole.logcallbackslength; // #=> 2
Copyright (c) 2011 Alpha Hydrae
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.