You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
624 B

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