throw error when returning false in Ox.forEach; remove Ox.sub

This commit is contained in:
rolux 2012-05-24 12:19:23 +02:00
parent 75baeb73f8
commit f6b06d0975

View file

@ -183,16 +183,14 @@ Ox.forEach = function(col, fn, that) {
for (key in col) {
// Ox.hasOwn(obj, key) && fn.call(that, col[key], key, col);
if (Ox.hasOwn(col, key) && fn.call(that, col[key], key, col) === false) {
console.warn('Returning false in Ox.forEach is deprecated.')
break;
throw new Error('Returning false in Ox.forEach is deprecated.');
}
}
} else {
for (i = 0; i < col.length; i++) {
// i in col && fn.call(that, col[i], i, col);
if (i in col && fn.call(that, col[i], i, col) === false) {
console.warn('Returning false in Ox.forEach is deprecated.')
break;
throw new Error('Returning false in Ox.forEach is deprecated.');
}
}
}
@ -624,36 +622,6 @@ Ox.some = function(obj, fn) {
}).length > 0;
};
/*@
Ox.sub <f> Returns a substring or sub-array
Ox.sub behaves like collection[start:stop] in Python
(or, for strings, like str.substring() with negative values for stop)
> Ox.sub([1, 2, 3], 1, -1)
[2]
> Ox.sub('foobar', 1)
"oobar"
> Ox.sub('foobar', -1)
"r"
> Ox.sub('foobar', 1, 5)
"ooba"
> Ox.sub('foobar', 1, -1)
"ooba"
> Ox.sub('foobar', -5, 5)
"ooba"
> Ox.sub('foobar', -5, -1)
"ooba"
> Ox.sub('foo', -1, 0)
""
@*/
Ox.sub = function(col, start, stop) {
stop = Ox.isUndefined(stop) ? col.length : stop;
start = start < 0 ? col.length + start : start;
stop = stop < 0 ? col.length + stop : stop;
return Ox.isArray(col) ? Ox.filter(col, function(val, key) {
return key >= start && key < stop;
}) : col.substring(start, Math.max(start, stop));
}
/*@
Ox.sum <f> Returns the sum of the values of a collection
> Ox.sum(1, 2, 3)