使用定时器分解任务

使用定时器分解任务主要是针对那些比较影响性能,阻塞页面进程且无需同步的逻辑

function processArray(items,process,callback){
      var todo=items.concat();
      setTimeout(function(){
           process(todo.shift());
           if(todo.length>0){
                  setTimeout(arguments.callee,25)
           }
      },25);
}    

  

原文地址:https://www.cnblogs.com/KingUp/p/5656376.html