首先先上模拟代码
Insert title herevar result = createData();
function createData() {
var result = [];
for (var index = 0; index < 900000; index++) {
result.push(index);
}
return result;
}
/**
* 模拟jquery的each循环
*/
function each(arr, fn) {
for (var index = 0, len = arr.length; index < len; index++) {
fn.call(null, arr[index], index, arr);
}
}
var start = new Date().getTime();
var testNum = 3;
// each循环
each(result, function(item) {
testNum += item;
});
var end = new Date().getTime();
// IE8下1530左右
console.log(end - start);
start = new Date().getTime();
testNum = 3;
// normal循环
for (var index =