throw error when returning false in Ox.loop; remove Ox._loop

This commit is contained in:
rolux 2012-05-24 12:18:01 +02:00
parent c03e7be035
commit 75baeb73f8

View file

@ -259,9 +259,9 @@ Ox.loop = function() {
i;
try {
for (i = start; step > 0 ? i < stop : i > stop; i += step) {
// fn(i);
if (fn(i) === false) {
console.warn('Returning false in Ox.loop is deprecated.')
break;
throw new Error('Returning false in Ox.loop is deprecated.');
}
}
} catch(e) {
@ -272,47 +272,6 @@ Ox.loop = function() {
return i;
};
Ox._loop = function() {
var type = Ox.makeArray(arguments).map(function(arg) {
return Ox.typeOf(arg);
}),
fnIndex = type.indexOf('function'),
callbackIndex = type.lastIndexOf('function'),
nIndex = callbackIndex - 1,
hasStart = type[1] == 'number',
hasStep = hasStart && type[2] == 'number',
hasCallback = fnIndex != callbackIndex,
hasN = hasCallback && type[nIndex] == 'number',
start = hasStart ? arguments[0] : 0,
stop = arguments[hasStart ? 1 : 0],
step = hasStep ? arguments[2] : (start <= stop ? 1 : -1),
fn = arguments[fnIndex],
n = hasN ? arguments[nIndex] / step : 1,
callback = hasCallback ? arguments[callbackIndex] : null;
function loop(start_, stop_, callback_) {
var i, isFalse;
for (i = start_; step > 0 ? i < stop_ : i > stop_; i += step) {
if (isFalse = fn(i) === false) {
break;
}
}
callback_ && callback_(i, !isFalse);
return i;
}
function next(start_) {
setTimeout(function() {
loop(start_, Math.min(start_ + n, stop), function(i, ret) {
(ret && i < stop ? next : callback)(i);
});
});
}
if (hasCallback) {
next(start);
} else {
return loop(start, stop);
}
};
/*@
Ox.print <f> Prints its arguments to the console
(arg, ...) -> <s> String