Show:

EventEmitter represents an asynchronous channel for broadcasting and receiving events.

Constructor

Events.EventEmitter

()

Example:

 var eventEmitter = new EventEmitter();
        
         eventEmitter.on('send', function(payload){
             console.log(payload) // {data : 0}
         });
        
         // sometime later...
         eventEmitter.emit('send', {data : 0});

Item Index

Methods

bindThis

(
  • owner
)

A convenience method to bind the provided object to all added handlers.

Parameters:

  • owner Object

    Bound this context

emit

(
  • type
  • data
)

Broadcast an event on the type channel with an optional payload. This will call the handlers of all EventEmitters listening on the type channel with the (optional) data payload as its argument.

Parameters:

off

(
  • [type]
  • [handler]
)

Removes the handler from the type channel. This undoes the work of on. If no type is provided, then all event listeners are removed. If a type is provided but no handler, then all listeners of that type are removed.

Parameters:

  • [type] String optional

    Channel name

  • [handler] Function optional

    Callback

on

(
  • type
  • handler
)

Adds a handler to the type channel which will be executed on emit.

Parameters:

once

(
  • type
  • handler
)

Behaves like EventEmitter.prototype.on, except the handler is only executed once.

Parameters:

trigger

()

Alias for emit.