Is it possible to create custom events in objects? Something like this
var myCustomClass = function (param) {
this.param = param;
};
myCustomClass.prototype.start = function(){
//Do staff
//fire event started
let event = new Event("started", {isStarted: true});
this.dispatchEvent(event);
}
And in mai.js create an instance of myCustomClass
myCustomClass = new myCustomClassr(param);
myCustomClass.addEventListener('started', function () {
console.log("started");
});
myCustomClass.start();
With this code I am getting an error telling me that dispatchEvent
is not a function