Oliver Roick

Introducing SuperSimpleEvents

Across various personal and professional projects, I needed a simple solution to extend prototypes with eventing functionality in JavaScript that is independent from third-party extensions. SuperSimpleEvents is my solution — a super simple event emitter for JavaScript.

Usage is simple:

(1) Extend your prototypes with eventing functions

function YourPrototype() {
    // Do stuff here
}

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

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

(2) 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);

(3) Remove an event listener

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

(4) Emit an event

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

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

Simple as that. Get in touch, if you want to know more.