listen-js
Version:
Easily add, remove, and trigger events on anything
25 lines (16 loc) • 553 B
Markdown
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
```javascript
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);
```