Le constructeur EventTarget()
crée une nouvelle instance d'objet EventTarget
.
Syntaxe
var myEventTarget = new EventTarget();
Paramètres
Aucun.
Valeur retournée
Une instance d'objet EventTarget
.
Exemples
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
Spécifications
Spécification | Statut | Commentaire |
---|---|---|
DOM La définition de 'EventTarget() constructor' dans cette spécification. |
Standard évolutif |
Compatibilité des navigateurs
BCD tables only load in the browser
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.