Skip to content

Instantly share code, notes, and snippets.

@Janking
Created May 26, 2015 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Janking/52bd4244ef181cf98139 to your computer and use it in GitHub Desktop.
Save Janking/52bd4244ef181cf98139 to your computer and use it in GitHub Desktop.
分时函数
var timeChunk = function(ary,fn,count){
var obj,t;
var len = ary.length;
var start = function(){
for(var i = 0 ;i<Math.min(count || 1 , ary.length);i++){
var obj = ary.shift();
fn(obj);
}
};
return function(){
t = setInterval(function(){
if(ary.length === 0){
return clearInterval(t);
}
start();
},200);
}
}
var ary = [];
for (var i = 0; i < 10000; i++) {
ary.push(i);
}
var renderFriendList = timeChunk(ary,function(n){
var div = document.createElement('div');
div.innerHTML = n;
document.body.appendChild(div);
},8);
renderFriendList()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment