SharedWorker
使用消息端口与 交换消息ParentWorker
。
家长工人
var port = new SharedWorker('/worker.js').port;
port.onmessage = function(e){
console.log(e.data);
};
port.start();
port.postMessage("Hello Shared Worker. I'm Mr. Tab");
SharedWorker (worker.js)
onconnect = function(e){
var port = e.ports[0];
port.onmessage = function(e){
console.log(e.data);
};
port.start();
port.postMessage("Hello Mr. Tab. I'm Shared Worker.");
};
Service Worker 呢?有没有类似SharedWorker
端口的东西?