event_target.js 639 B

123456789101112131415161718192021222324252627282930
  1. 'use strict';
  2. var Event = require('./event');
  3. var EventTarget = {
  4. onopen: null,
  5. onmessage: null,
  6. onerror: null,
  7. onclose: null,
  8. addEventListener: function(eventType, listener, useCapture) {
  9. this.on(eventType, listener);
  10. },
  11. removeEventListener: function(eventType, listener, useCapture) {
  12. this.removeListener(eventType, listener);
  13. },
  14. dispatchEvent: function(event) {
  15. event.target = event.currentTarget = this;
  16. event.eventPhase = Event.AT_TARGET;
  17. if (this['on' + event.type])
  18. this['on' + event.type](event);
  19. this.emit(event.type, event);
  20. }
  21. };
  22. module.exports = EventTarget;