Created
May 26, 2015 13:14
-
-
Save Janking/52bd4244ef181cf98139 to your computer and use it in GitHub Desktop.
分时函数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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