Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including event-hijack with all npm packages installed. Try it out:

var eventHijack = require("event-hijack")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

event-hijack v0.0.1

Hijacks the specified EventEmitter event


Hijacks the specified EventEmitter event

Hijacks the specified EventEmitter event name.


$ npm install event-hijack


var hijack = require('event-hijack');
var EventEmitter = require('events').EventEmitter;

// our test subjet "emitter" instance
var emitter = new EventEmitter();

// you can use the emitter normally
emitter.on('thing', function () {
  console.log('got "thing"');


// once you "hijack" the event, subsequent listeners added for that
// event will *not* be added as regular listeners for that event
var emitThing = hijack(emitter, 'thing', function () {
  console.log('this is an *original* "thing" event');

// this will *not* be a "thing" listener. instead, you must
// invoke `emitThing()` for this callback to be invoked
emitter.on('thing', function () {
  console.log('this is a *hijacked* event listener');

// emit a fake "thing" event, the original listener will not be invoked,
// but the hijacked listener *will* be invoked


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free