class Model {
constructor( initObj ){
this.eventer = new EventTarget();
this.dispatchEvent = this.eventer.dispatchEvent
}
run(){
// works
this.eventer.dispatchEvent( new CustomEvent('sessionEvent', { detail:1 } ) )
// Uncaught (in promise) TypeError: Illegal invocation
this.dispatchEvent( new CustomEvent('sessionEvent', { detail:1 } ) )
}
}
OR
What is the best way to enable dispatchEvent functionality in my class? Ideally to use it like so:
model.addEventListener('someEvent' , onSomeEvent )