这篇翻译不完整。请帮忙从英语翻译这篇文章

EventTarget() 构造方法将会创建一个新的EventTarget 对象实例。

语法

var myEventTarget = new EventTarget();

参数

无。

返回值

一个 EventTarget 实例。

例子

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
EventTarget() constructor
Living Standard  

浏览器兼容性

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
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Basic supportChrome Full support 64Edge ? Firefox Full support 59IE No support NoOpera Full support 51Safari No support NoWebView Android Full support 64Chrome Android Full support 64Edge Mobile ? Firefox Android Full support 59Opera Android Full support 51Safari iOS No support NoSamsung Internet Android No support No

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown

另见

 

文档标签和贡献者

此页面的贡献者: rxxy
最后编辑者: rxxy,