2

我尝试在 JS 中创建一种新的 Worker 类:

function ConnectedWorker(workerSrcURL, onConnect) {
  function filterOnConnect(rawPort, url) {
    if (url.indexOf(workerSrcURL) !== -1)
      onConnect(rawPort, url);
  }
  ChannelPlate.PortServer(workerSrcURL, filterOnConnect);

  Worker.call(this, workerSrcURL);
  this.onmessage = onConnect;
}
ConnectedWorker.prototype = {
  __proto__: Worker.prototype
};

但它在 Worker.call() 上失败了

Uncaught TypeError: Failed to constructor 'Worker': Please use the 'new' operator, 这个 DOM 对象构造函数不能作为函数调用。

有什么提示吗?

4

0 回答 0