mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 08:07:50 +00:00
adding breakLoop
This commit is contained in:
@@ -90,7 +90,7 @@
|
||||
_.each(obj, function(value, index, list) {
|
||||
if (iterator.call(context, value, index, list)) {
|
||||
result = value;
|
||||
throw '__break__';
|
||||
_.breakLoop();
|
||||
}
|
||||
});
|
||||
return result;
|
||||
@@ -123,7 +123,7 @@
|
||||
if (obj.every) return obj.every(iterator, context);
|
||||
var result = true;
|
||||
_.each(obj, function(value, index, list) {
|
||||
if (!(result = result && iterator.call(context, value, index, list))) throw '__break__';
|
||||
if (!(result = result && iterator.call(context, value, index, list))) _.breakLoop();
|
||||
});
|
||||
return result;
|
||||
};
|
||||
@@ -135,7 +135,7 @@
|
||||
if (obj.some) return obj.some(iterator, context);
|
||||
var result = false;
|
||||
_.each(obj, function(value, index, list) {
|
||||
if (result = iterator.call(context, value, index, list)) throw '__break__';
|
||||
if (result = iterator.call(context, value, index, list)) _.breakLoop();
|
||||
});
|
||||
return result;
|
||||
};
|
||||
@@ -146,7 +146,7 @@
|
||||
if (_.isArray(obj)) return _.indexOf(obj, target) != -1;
|
||||
var found = false;
|
||||
_.each(obj, function(value) {
|
||||
if (found = value === target) throw '__break__';
|
||||
if (found = value === target) _.breakLoop();
|
||||
});
|
||||
return found;
|
||||
};
|
||||
@@ -446,6 +446,11 @@
|
||||
return value;
|
||||
};
|
||||
|
||||
// Break out of the middle of an iteration.
|
||||
_.breakLoop = function() {
|
||||
throw "__break__";
|
||||
};
|
||||
|
||||
// Generate a unique integer id (unique within the entire client session).
|
||||
// Useful for temporary DOM ids.
|
||||
var idCounter = 0;
|
||||
|
||||
Reference in New Issue
Block a user