I want to inherit EventTarget object.
So I tried the following code, which causes an error "Illegal constructor".
class OwnClass extends EventTarget {
constructor () {
super();
}
}
function eventHandler () {
console.log( arguments );
}
let et = new OwnClass();
et.addEventListener( "Own Event", eventHandler );
et.dispatchEvent( new Event( "Own Event" ) );
So I use following code, currently.
class OwnClass extends Document {
constructor () {
super();
}
}
function eventHandler () {
console.log( arguments );
}
let et = new OwnClass();
et.addEventListener( "Own Event", eventHandler );
et.dispatchEvent( new Event( "Own Event" ) );
But this cause meaningless memory usage.
Is there a way to inherit EventTarget directly?