function multistep(steps, args, callback){
var tasks = steps.concat();
setTimeout(function(){
//执行下一个任务
var task = tasks.shift();
task.apply(null, args || []));
//检查是否还有其他任务
if(tasks.length > 0){
setTimeout(arguments.callee);
}else{
callback();
}
},25);
}
5、记录代码运行时间
var start = new Date();
stop;
someLongProcess();
stop = +new Date();
***********改进***处理数组代替循环*******************
function processArray(items, process, callback){
var todo = items.concat();
setTimeout(function(){
var start = +new Date();
function startWorker()
{
if(typeof(Worker)!=="undefined")
{
if(typeof(w)=="undefined")
{
w=new Worker("demo_workers.js");
}
w.onmessage = function (event) {
document.getElementById("result").innerHTML=event.data;
};
}
else
{
document.getElementById("result").innerHTML="Sorry, your browser
does not support Web Workers...";
}
}
function stopWorker()
{
w.terminate();
}
</script>