Emitter
Module | ejs |
Definition | class Emitter |
Inheritance | Emitter ![]() |
Stability | Prototype. |
Example | events.on(event, function (event, ...args) { // Do something }).fire("topic", 1, 2, 3) @stability prototype |
The emitter class provides a publish/subscribe model of communication via events.
It supports the registration of observers who want to subscribe to events of interest.
Properties
(No own properties defined)
Emitter Class Methods
Qualifiers | Method |
---|
Emitter Instance Methods
Qualifiers | Method |
---|---|
Emitter() | |
Construct a new event Emitter object. | |
clearObservers(name: Object = null): Void | |
Clear observers for a given event name. | |
fire(name: String, args: Array): Void | |
Emit an event to the registered observers. | |
getObservers(name: String): Array | |
Return the observers for this emitter. | |
fireThis(name: String, thisObj: Object, args: Array): Void | |
Emit an event to the registered observers using an explict value for the "this" object. | |
hasObservers(): Boolean | |
Determine if the emitter has any observers. | |
off(name: Object, callback: Function): Void | |
Turn off and remove a registered observer. | |
on(name: Object, callback: Function): Emitter | |
Add an observer for a set of named event. |
Method Detail
Emitter()
- Description
- Construct a new event Emitter object.
- Description
- Clear observers for a given event name.
- Parameters
name: Object Event name to clear. The name can be a string or an array of event strings. If null, observers for all event names are cleared. [default: null]
- Description
- Return the observers for this emitter.
- Parameters
name: String Event name to fire to the observers.
- Returns
- An array of observer endpoints. These are cloned and not the actual observer objects. 8.
- Description
- Emit an event to the registered observers using an explict value for the "this" object.
hasObservers(): Boolean
- Description
- Determine if the emitter has any observers.
- Returns
- True if there are currently registered observers.
- Description
- Add an observer for a set of named event. The callback will be invoked when the requested event is fired by calling Emitter.fire. When the callback runs, it will be invoked with the value of "this" relevant to the context of the callback. If the callback is a class method, the value of "this" will be the object instance. Global functions will have "this" set to the global object. Use Function.bind to override the bound "this" value.