mirror of
https://github.com/nodejs/node.git
synced 2025-05-09 19:38:23 +00:00

As per the discussion in #734, this patch deprecates the usage of `EventEmitter.listenerCount` static function in the docs, and introduces the `listenerCount` function in the prototype of `EventEmitter` itself. PR-URL: https://github.com/nodejs/node/pull/2349 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
19 lines
593 B
JavaScript
19 lines
593 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const EventEmitter = require('events');
|
|
|
|
const emitter = new EventEmitter();
|
|
emitter.on('foo', function() {});
|
|
emitter.on('foo', function() {});
|
|
emitter.on('baz', function() {});
|
|
// Allow any type
|
|
emitter.on(123, function() {});
|
|
|
|
assert.strictEqual(EventEmitter.listenerCount(emitter, 'foo'), 2);
|
|
assert.strictEqual(emitter.listenerCount('foo'), 2);
|
|
assert.strictEqual(emitter.listenerCount('bar'), 0);
|
|
assert.strictEqual(emitter.listenerCount('baz'), 1);
|
|
assert.strictEqual(emitter.listenerCount(123), 1);
|