var i=0;
self.onmessage=function(event)
{
//console.log(event)
postMessage(event.data+1)
}
function test()
{
postMessage(i++)
setTimeout(() => {
test()
}, 100);
}
test();

这样起两个worker线程

w = new Worker("aa.js");
w.onmessage = function (event) {
//console.log(event)
i=event.data
mesh.position.y=Math.sin(i)
};
//
w2=new Worker("aa.js")
w2.onmessage=function(event)
{
i=event.data
mesh.position.x=Math.sin(i)
}

这样可以放在webworker来计算一些东西