From 5141a51298c0c4ef02219ec404736a425ebf3da9 Mon Sep 17 00:00:00 2001 From: shinuza Date: Sat, 7 May 2011 16:29:43 +0200 Subject: [PATCH] Refactored fix as suggested in https://github.com/documentcloud/underscore/issues/177 --- underscore.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/underscore.js b/underscore.js index 1119eb400..d007edf57 100644 --- a/underscore.js +++ b/underscore.js @@ -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`.