The EventTarget() constructor creates a new EventTarget object instance.

Syntax

var myEventTarget = new EventTarget();

Parameters

None.

Return value

An instance of the EventTarget object.

Examples

class MyEventTarget extends EventTarget {
  constructor(mySecret) {
    super();
    this._secret = mySecret;
  }

  get secret() { return this._secret; }
};

let myEventTarget = new MyEventTarget(5);
let value = myEventTarget.secret;  // == 5
myEventTarget.addEventListener("foo", function(e) {
  this._secret = e.detail;
});

let event = new CustomEvent("foo", { detail: 7 });
myEventTarget.dispatchEvent(event);
let newValue = myEventTarget.secret; // == 7

Specifications

Specification Status Comment
DOM
The definition of 'EventTarget() constructor' in that specification.
Living Standard  

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support64 ?59 No51 No
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support6464 ?5951 No No

See also

 

Document Tags and Contributors

 Contributors to this page: fscholz, chrisdavidmills, ziyunfei
 Last updated by: fscholz,