Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

js.event_emitter

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js.event_emitter

Event emitter for es6 classes

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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(                              // attach event handler, call on every trigger
	"run",                           // event name
	dog.gav,                         // event handler
	dog                              // callback context
);

cat.one( "run", dog.manyGav, dog );  // call on first trigger

cat.trigger( "run" );                // > "Bob gav"
                                     // > "Bob gav gav gav"
cat.trigger( "run" );                // > "Bob gav"
cat.trigger( "run" );                // > "Bob gav"

cat.off();                           // detach all handlers of all events
cat.off( "run" );                    // detach all handlers of "run" event
cat.off( "run", dog.gav );           // detach dog.gav handler of "run" event
cat.off( "run", dog.gav, dog );      // detach dog.gav handler of "run" event when context is dog

FAQs

Package last updated on 22 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc