From efb1f4c577c4ae2dfcdd79a4605831045f1e3156 Mon Sep 17 00:00:00 2001 From: Matt Chapman Date: Mon, 22 Jul 2013 18:37:04 -0700 Subject: [PATCH] improve consistency in existence functions --- underscore.util.existential.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/underscore.util.existential.js b/underscore.util.existential.js index 9fd72fe..64ffd62 100644 --- a/underscore.util.existential.js +++ b/underscore.util.existential.js @@ -13,19 +13,20 @@ // Helpers // ------- - + // Mixing in the truthiness // ------------------------ _.mixin({ - exists: function(x) { return x != null; }, + exists: function(x) { return typeof x !== "undefined" && x !== null; }, truthy: function(x) { return (x !== false) && _.exists(x); }, falsey: function(x) { return !_.truthy(x); }, not: function(b) { return !b; }, firstExisting: function() { for (var i = 0; i < arguments.length; i++) { - if (arguments[i] != null) return arguments[i]; + if (_.exists(arguments[i])) return arguments[i]; } + return undefined; } });