JAVASCRIPT   65

event_target.js

Guest on 21st August 2021 08:51:13 PM

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

Raw Paste


Login or Register to edit or fork this paste. It's free.