Home > Web Front-end > JS Tutorial > Instructions for using the events.emitter.listeners method in node.js_node.js

Instructions for using the events.emitter.listeners method in node.js_node.js

WBOY
Release: 2016-05-16 16:27:40
Original
1419 people have browsed it

Method description:

All listeners registered for the specified event will be returned as an array.

Grammar:

Copy code The code is as follows:

emitter.listeners(event)

Receive parameters:

event Specified event

Example:

Copy code The code is as follows:

server.on('connection', function (stream) {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// [[Function] ]

Source code:

Copy code The code is as follows:

EventEmitter.prototype.listeners = function(type) {
var ret;
if (!this._events || !this._events[type])
ret = [];
else if (util.isFunction(this._events[type]))
ret = [this._events[type]];
else
ret = this._events[type].slice();
Return ret;
};
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template