我想使用_.every方法(不使用_.each方法因为我无法打破它_.each循环)来遍历数组并在某个条件下中断遍历。所以我想知道是_.every方法是同步还是不同步?
答案 0 :(得分:1)
是同步
function every(collection, callback, thisArg) {
var result = true;
callback = lodash.createCallback(callback, thisArg, 3);
var index = -1,
length = collection ? collection.length : 0;
if (typeof length == 'number') {
while (++index < length) {
if (!(result = !!callback(collection[index], index, collection))) {
break;
}
}
} else {
forOwn(collection, function(value, index, collection) {
return (result = !!callback(value, index, collection));
});
}
return result;
}