我在 JavaScript 代码中使用 Web Worker,我使用 Worker 的类如下所示:
class EnemyMoveCalculater {
constructor() {
this.worker = null;
}
startMoveCalculation(boardData, nextPlayer, jokerReady, enemyMoveHandlerCallback) {
this.worker = new Worker('js/calculateEnemyMoves.js');
this.worker.onmessage = function(e) {
this.worker.terminate();
this.worker = null;
enemyMoveHandlerCallback(e.data);
}.bind(this);
this.worker.postMessage([boardData, nextPlayer, jokerReady]);
}
terminateMoveCalculation() {
if (this.worker) this.worker.terminate();
}
}
Run Code Online (Sandbox Code Playgroud)
我的网站可在 Firefox(适用于 Windows 和 Android)、Edge 和 Samsung 互联网浏览器中运行。但是,当“startMoveCalculation”在 Safari(版本 12.1.2)中运行时,我收到以下错误:
ReferenceError: Can't find variable: Worker
Run Code Online (Sandbox Code Playgroud)
可能是什么问题呢?