不,它正在阻止。看一下算法的规格。但是,在MDN上给出了一个可能更容易理解的实现:
if (!Array.prototype.forEach){ Array.prototype.forEach = function(fun ) { "use strict"; if (this === void 0 || this === null) throw new TypeError(); var t = Object(this); var len = t.length >>> 0; if (typeof fun !== "function") throw new TypeError(); var thisp = arguments[1]; for (var i = 0; i < len; i++) { if (i in t) fun.call(thisp, t[i], i, t); } };}如果必须为每个元素执行很多代码,则应考虑使用其他方法:
function processArray(items, process) { var todo = items.concat(); setTimeout(function() { process(todo.shift()); if(todo.length > 0) { setTimeout(arguments.callee, 25); } }, 25);}然后调用:
processArray([many many elements], function () {lots of work to do});那时这将是非阻塞的。该示例摘自 High PerformanceJavascript 。



