Super simple event emitter for JavaScript
JavaScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
tests
.gitignore
.travis.yml
Gruntfile.js
LICENSE
README.md
package.json

README.md

SuperSimpleEvents

Build Status Coverage Status

SuperSimpleEvents is a super simple event emitter for JavaScript.

How to use

Extend your prototype with EventEmitter:

// Create the Prototype to be extended
function YourPrototype() {
    ...
}

// Extend the prototype
YourPrototype.prototype = new EventEmitter();

// Reset the constructor to YourPrototype
YourPrototype.constructor = YourPrototype;

Register an event listener

function callback(params) {
    // do something with the params returned by the event emitter
    console.log(params.something); // new-value
}

var emitter = YourPrototype();
emitter.registerListener('something:changed', callback);

Remove an event listener

emitter.removeListener('event-name', callback);

Emit an event

YourPrototype.prototype.changeSomething() = function () {
    // Change something

    this.emitEvent('something:changed', {something: 'new-value'})
}