EventTarget()
O construtor EventTarget()
cria uma nova instância do objeto EventTarget
.
Sintaxe
var myEventTarget = new EventTarget();
Parâmetros
Nenhum.
Retorno de valor
Uma instância do objeto EventTarget
.
Exemplos
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
Specificações
Specification | Status | Comment |
---|---|---|
DOM The definition of 'EventTarget() constructor' in that specification. |
Padrão em tempo real |
Compatibilidade com navegadores
BCD tables only load in the browser