在work.html中
var data = [1,2,3,4], worker = new Worker('work1.js'); worker.onmessage = function(e){ var data = e.data; console.log('sorted:' + data); } worker.postMessage(data);
在work1.js中
self.onmessage = function(e){ var data = e.data; data.sort(function(a,b){ return b-a; }); self.postMessage(data); }
importScripts('w2.js','w1.js');
//异步下载,但是按照顺序执行