方法说明:
注册了指定event的所有监听器将被作为数组返回。
语法:
emitter.listeners(event)
接收参数:
event 指定事件
例子:
server.on('connection', function (stream) {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// [ [Function] ]
源码:
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;
};