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.

Parameters:

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:

  • type String

    Event type key (for example, 'click')

  • handler Function

    Callback

trigger

()

Alias for emit.