我做了一个webworker并尝试添加一个名为progress的自定义事件,如下所示:
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));
};
Run Code Online (Sandbox Code Playgroud)
在父JavaScript上:
scope.worker.addEventListener('progress', (e) => { //cannot add custom events to worker yet
scope.progress = e.data;
});
Run Code Online (Sandbox Code Playgroud)
问题是事件永远不会被触发,从我读过的内容来看,似乎消息和错误是唯一附加到worker对象的事件.是否无法添加自定义事件?