我做了一个webworker,并尝试添加一个称为progress的自定义事件,如下所示:
问题在于事件从未触发,根据我所读的,似乎只有消息和错误事件与worker对象相关联。是否不可能添加自定义事件?
self.updateProgress = function(no){
let event = new CustomEvent(
'progress',
{
detail : {
description: "event from webworker to update progress",
timeofevent: new Date(),
eventcode: 15
},
bubbles: true,
cancelable: false,
data : no
});
self.console.log(self.dispatchEvent(event));
};
在父级JavaScript中:
scope.worker.addEventListener('progress', (e) => { //cannot add custom events to worker yet
scope.progress = e.data;
});
问题在于事件从未触发,根据我所读的,似乎只有消息和错误事件与worker对象相关联。是否不可能添加自定义事件?