listen-js
v1.0.1
Published
Easily add, remove, and trigger events on anything
Downloads
61
Maintainers
Readme
ListenJS
A small, lightweight library that adds addEventListener(), removeEventListener(), and dispatchEvent() methods to any object.
The event listener methods follow the EventTarget (https://developer.mozilla.org/en-US/docs/Web/API/EventTarget) API, also allowing this library to serve as a polyfill.
Usage
var obj = {};
Listen.createTarget(obj);
// listen to the "wee" event
obj.addEventListener('wee', function () {
// wee was trigger!
});
// trigger the event
obj.dispatchEvent('wee');
Listen.destroyTarget(obj);