throw error when returning false in Ox.forEach; remove Ox.sub
This commit is contained in:
parent
75baeb73f8
commit
f6b06d0975
1 changed files with 2 additions and 34 deletions
|
@ -183,16 +183,14 @@ Ox.forEach = function(col, fn, that) {
|
||||||
for (key in col) {
|
for (key in col) {
|
||||||
// Ox.hasOwn(obj, key) && fn.call(that, col[key], key, 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) {
|
if (Ox.hasOwn(col, key) && fn.call(that, col[key], key, col) === false) {
|
||||||
console.warn('Returning false in Ox.forEach is deprecated.')
|
throw new Error('Returning false in Ox.forEach is deprecated.');
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < col.length; i++) {
|
for (i = 0; i < col.length; i++) {
|
||||||
// i in col && fn.call(that, col[i], i, col);
|
// i in col && fn.call(that, col[i], i, col);
|
||||||
if (i in col && fn.call(that, col[i], i, col) === false) {
|
if (i in col && fn.call(that, col[i], i, col) === false) {
|
||||||
console.warn('Returning false in Ox.forEach is deprecated.')
|
throw new Error('Returning false in Ox.forEach is deprecated.');
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -624,36 +622,6 @@ Ox.some = function(obj, fn) {
|
||||||
}).length > 0;
|
}).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 <f> Returns the sum of the values of a collection
|
||||||
> Ox.sum(1, 2, 3)
|
> Ox.sum(1, 2, 3)
|
||||||
|
|
Loading…
Reference in a new issue