listenme
v1.0.0
Published
[![Build Status](https://travis-ci.org/M1nified/ListenMe.js.svg?branch=master)](https://travis-ci.org/M1nified/ListenMe.js)
Downloads
2
Maintainers
Readme
ListenMe.js
Simply add event listeners for nonDOM objects in JavaScript.
Installation
In command line
npm install listenme --save
Basic usage NodeJS
Require
var listenme = require('listenme');
Use
listenme.listenme.call(objectToListenOn);
or
listenme.listenme(objectToListenOn);
Basic usage browser
<script src="./node_modules/listenme/build/aio.js"></script>
Example
...
class SomeClass{
constructor(){
listenme.listenme.call(this); // or ListenMe.listenme.call(this);
this.event1 = this.addEventListener('event1',()=>{
console.log('event1');
})
}
example(){
this.dispatchEvent('event1'); // true - event exists
console.log('example');
this.dispatchEvent('event2'); // false - event not defined
}
}
let sc = new SomeClass();
sc.example(); // Output:
// event1
// example
sc.removeEventListener(sc.event1); // removes event1
sc.example(); // Output:
// example