events-es5
Browser support
Chrome, Safari, Firefox, Opera, IE9+
( If you want to use this module in IE8-, you need to modify events.js
to replace the use
of Array.prototype.slice(), .etc )
Installation
npm install events-es5 or jspm install npm:events-es5
Usage
You can use it both in node.js environment and in a browser.
- Use it as a Node module.
// a.js var Events = ; var { thisevents = 'message' 'error'; // Initialize events. }; WorkerManagerprototype = { thisevents; // Dispatch messages to subscribers. } ; // b.js var { this; }; Companyprototype = { ... this_workerMgr = ; this_workerMgrevents // Subscribe. ; // Chainable. } { ; } ... ;
- Use it directly in a browser. You can simply put
events.js
in your project and include it by htmlscript
tag.
// a.js var { thisevents = 'message' 'error'; // Initialize events. }; // Before you use it in browsers, you probably will want to replace 'nameSpace' with a real // namespace. Simply update events.js. ... ...
- Other methods in this module. ( The code of
events.js
is clean and well organized, I recommend you read it directly.)
/** * Defines a list of events. * @param eventNames {String...} * @returns */ // e.g. declare('message', 'error'); /** * Returns whether <eventName> has been defined. * @param eventName * @returns */ // e.g. isSupported('message'); /** * Binds a listener to '_activate' event, this listener * will be noticed when any public event starts to have listeners. * * @param fn * @returns */ /** * Binds a listener to '_deactivate' event, this listener * will be noticed when any public event have no listeners. * * @param fn * @returns */
Tests
npm test