您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

symbols.js 627B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. var common = require('./common');
  3. var EventEmitter = require('../');
  4. var assert = require('assert');
  5. var ee = new EventEmitter();
  6. var foo = Symbol('foo');
  7. var listener = common.mustCall();
  8. ee.on(foo, listener);
  9. assert.strictEqual(ee.listeners(foo).length, 1);
  10. assert.strictEqual(ee.listeners(foo)[0], listener);
  11. ee.emit(foo);
  12. ee.removeAllListeners();
  13. assert.strictEqual(ee.listeners(foo).length, 0);
  14. ee.on(foo, listener);
  15. assert.strictEqual(ee.listeners(foo).length, 1);
  16. assert.strictEqual(ee.listeners(foo)[0], listener);
  17. ee.removeListener(foo, listener);
  18. assert.strictEqual(ee.listeners(foo).length, 0);