Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Evented JavaScript for the browser
JavaScript

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
src
test
README.md
makefile

README.md

EventEmitter

Evented JavaScript for the browser

This script adds the EventEmitter class to your browser or any other environment such as node.js.

So you can listen for and emit events from what ever objects you choose.

For more information such as documentation and examples you can either skim over the rest of this readme or visit the wiki. Any contribution to the wiki are much appreciated.

Example

// Initialise the EventEmitter
var ee = new EventEmitter();

// Initialise the listener function
function myListener() {
    console.log('The foo event was emitted.');
}

// Add the listener
ee.addListener('foo', myListener);

// Emit the foo event
ee.emit('foo'); // The listener function is now called

// Remove the listener
ee.removeListener('foo', myListener);

// Log the array of listeners to show that it has been removed
console.log(ee.listeners('foo'));

Tests

EventEmitter is tested and working in the following browsers.

  • Chrome
  • Firefox
  • Safari
  • Opera
  • IE 5+

If you test it in something a little more obscure, please let me know how it turned out.

To test, simply run test.html in the test folder.

License

Creative Commons License

EventEmitter by Oliver Caldwell is licensed under a Creative Commons Attribution 3.0 Unported License.

Something went wrong with that request. Please try again.