window.URL = window.URL || window.webkitURL;
const response = `self.onmessage = ({ data: { data } }) => {
const {method} = data;
self.postMessage(method.replace("吗",""));
}`;
const blob = new Blob([response],{ type: "application/javascript" });
const work = new Worker(URL.createObjectURL(blob));
work.onmessage = function (e) {
// speechSynthesis.speak(new SpeechSynthesisUtterance(e.data))
alert(`Response: ${JSON.stringify(e)}`);
// URL.revokeObjectURL(url);//释放内存
// worker.terminate();
};
worker.postMessage({
method: "吃饭了吗"
});
温馨提示:本文最后更新于2021年07月14日,已超过622天没有更新。如果文章内容或图片资源失效,请留言反馈,我会及时处理,谢谢!
版权声明:Shire 发表于 2021-7-14
转载请注明: 动态创建JS WORKER | Shire
转载请注明: 动态创建JS WORKER | Shire
评论