以下是主要js和worker js文件的代码:
main.js
function main(){
var loadShWorker = new Worker('worker.js');
var loadShWorkerMsgEvntListnr = function(e) {
console.log("reached main");
console.log('Worker said: ', e.data);
}
// loadShWorker.port.start();
loadShWorker.removeEventListener('onmessage',loadShWorkerMsgEvntListnr);
loadShWorker.addEventListener('onmessage', loadShWorkerMsgEvntListnr, false);
// loadShWorker.port.start();
// loadShWorker.port.postMessage('Hello World');
loadShWorker.postMessage('Hello World');
}
worker.js
console.log("reached worker top");
self.addEventListener('onmessage', function(e) {
console.log("reached worker");
self.postMessage(e.data);
console.log("posted msg from worker");
}, false);
此处控件未到达主js文件。我做了什么不同的