Refactored fix as suggested in

https://github.com/documentcloud/underscore/issues/177
This commit is contained in:
shinuza
2011-05-07 16:29:43 +02:00
parent 6846d71f88
commit 5141a51298

View File

@@ -180,19 +180,16 @@
// Determine if at least one element in the object matches a truth test.
// Delegates to **ECMAScript 5**'s native `some` if available.
// Aliased as `any`.
var any = _.some = _.any = function(obj, iterator, context) {
iterator || (iterator = _.identity);
var any = _.some = _.any = function (obj, iterator, context) {
iterator = iterator || _.identity;
var result = false;
if (obj == null) return result;
if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context);
each(obj, function(value, index, list) {
if (iterator.call(context, value, index, list)) {
result = true;
return breaker;
}
each(obj, function (value, index, list) {
if (result |= iterator.call(context, value, index, list)) return breaker;
});
return result;
};
return !!result;
}
// Determine if a given value is included in the array or object using `===`.
// Aliased as `contains`.