This commit is contained in:
rolux 2012-05-23 17:48:17 +02:00
parent c949b304ba
commit 77f4d8f3b9

View file

@ -32,7 +32,7 @@
(col, iterator[, that], callback[, ms]) -> <u> undefined
@*/
Ox.nonblockingForEach = function(col, iterator, that, callback, ms) {
var i, keys, last = Ox.last(arguments), n, time = +new Date();
var i, keys, last = Ox.last(arguments), n, time, type = Ox.typeOf(col);
callback = Ox.isFunction(last) ? last : arguments[arguments.length - 2];
col = type == 'array' || type == 'object' ? col : Ox.toArray(col);
keys = type == 'object' ? Object.keys(col) : Ox.range(col.length);
@ -41,6 +41,7 @@
that = arguments.length == 5 || (
arguments.length == 4 && Ox.isFunction(last)
) ? that : null;
time = +new Date();
iterate();
function iterate() {
keys[i] in col && iterator.call(that, col[keys[i]], keys[i], col, function() {
@ -49,7 +50,7 @@
iterate();
} else {
setTimeout(function() {
time += new Date();
time = +new Date();
iterate();
});
}