use worker without js file

时间:2023-11-26 09:48:32
  var blob = new Blob(['onmessage=function(e){postMessage(e.data);}']);
debugger;
// Obtain a blob URL reference to our worker 'file'.
var blobURL = window.URL.createObjectURL(blob); // create a Worker
var worker = new Worker(blobURL);
worker.onmessage = function (e) {
console.log(e.data);
};
worker.postMessage("Send some Data");