是否有可能(即使是不明智的)在另一个SharedWorker的处理程序中实例化SharedWorker?
// Code in sharedworker.js
onconnect = function(e) {
var port = e.ports[0];
port.onmessage = function(e) {
port.postMessage("Hello"); // This is sent.
var worker = new SharedWorker("worker.js");
post.postMessage("Goodbye"); // In my tests, this is not sent.
}
}
// Code in main.js
var worker = new SharedWorker('sharedworker.js');
worker.port.onmessage = function(e) {
window.console.log(e.data);
}
worker.port.postMessage("Start");
答案 0 :(得分:0)
那应该是port.postMessage("Goodbye");
而不是post.postMessage("Goodbye");
吗?