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 |
DOMThe definition of 'EventTarget() constructor' in that specification. | Living Standard |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
EventTarget() constructor
|
Chrome
Full support 64 |
Edge
Full support ≤79 |
Firefox
Full support 59 |
IE
No support No |
Opera
Full support 51 |
Safari
Full support 14 |
WebView Android
Full support 64 |
Chrome Android
Full support 64 |
Firefox Android
Full support 59 |
Opera Android
Full support 47 |
Safari iOS
Full support 14 |
Samsung Internet Android
Full support 9.0 |
Legend
- Full support
- Full support
- No support
- No support
See also
EventTarget() by Mozilla Contributors is licensed under CC-BY-SA 2.5.