是否可以在对象中创建自定义事件?像这样的东西
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);
}
并在 mai.js 创建一个实例myCustomClass
myCustomClass = new myCustomClassr(param);
myCustomClass.addEventListener('started', function () {
console.log("started");
});
myCustomClass.start();
使用此代码,我收到一条错误消息,告诉我这dispatchEvent
不是函数