Yielding Processes(数组分块)
1 function chunk(array, process, context) { 2 setTimeout(function() { 3 var item = array.shift(); 4 process.call(context, item); 5 6 if (array.length > 0) { 7 setTimeout(arguments.callee, 100); 8 } 9 }, 100); 10 } 11 12 var data = [12, 123, 1234, 453, 436, 23, 23, 5, 4123, 45, 346, 5634, 2234, 345, 342]; 13 14 function printValue(item) { 15 var div = document.getElementById("myDiv"); 16 div.innerHTML += item + " <br/> "; 17 } 18 chunk(data, printValue); 19 //克隆一个数组 20 //chunk(data.concat(), printValue);