Version0 /
EventsThis module, which is borrowed from Node.js, contains a single class definition, EventEmitter. A typical usage pattern is to inherit it. For example: var events = require('events'); var util = require('util'); function MyClass() { // Invoke the event emitter constructor. events.EventEmitter.call(this); util.log('instantiated'); } util.inherits(MyClass, events.EventEmitter); var instance = new MyClass(); instance.on('ping', function() { util.log('ping'); }); instance.emit('ping'); This code defines a class that subclasses EventEmitter. As a consequence, the class inherits the functions on() and emit(). The first of these functions defines what action to take when a named event is emitted. The last two lines of the code above define the reaction to an event named 'ping' and then emit the event. The result of executing this code is, for example: 2 May 14:16:33 - instantiated 2 May 14:16:33 - ping The events module is defined more fully at https://nodejs.org/api/events.html. It include the following:
Remote Resources
Back to Built-In JavaScript Modules |