Install
npm install js.event_emitter --save
Usage
import EventEmitter from "js.event_emitter";
class Cat extends EventEmitter {}
class Dog extends EventEmitter {
constructor(){
this.name = "Bob";
}
gav(){
console.log( this.name + " gav" );
}
manyGav(){
console.log( this.name + " gav gav gav" );
}
}
let dog = new Dog,
cat = new Cat;
cat.on(
"run",
dog.gav,
dog
);
cat.one( "run", dog.manyGav, dog );
cat.trigger( "run" );
cat.trigger( "run" );
cat.trigger( "run" );
cat.off();
cat.off( "run" );
cat.off( "run", dog.gav );
cat.off( "run", dog.gav, dog );