Home  >  Article  >  Web Front-end  >  Instructions for using the events.EventEmitter.listenerCount method in node.js_node.js

Instructions for using the events.EventEmitter.listenerCount method in node.js_node.js

WBOY
WBOYOriginal
2016-05-16 16:28:251544browse

Method description:

Returns the number of listeners registered for the specified event.

Syntax:

Copy code The code is as follows:

EventEmitter.listenerCount(emitter, event)

Receive parameters:

emitter Event Emitter
event event

Example:

Copy code The code is as follows:

if(events.EventEmitter.listenerCount(this, 'feedback') == 0) {
//....
}

Source code:

Copy code The code is as follows:

EventEmitter.listenerCount = function(emitter, type) {
var ret;
if (!emitter._events || !emitter._events[type])
ret = 0;
else if (util.isFunction(emitter._events[type]))
ret = 1;
else
ret = emitter._events[type].length;
Return ret;
};
Statement:
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