From c62d1e816f26859ee651de950384d4cf4cab9ce4 Mon Sep 17 00:00:00 2001 From: Shaun Guth Date: Fri, 26 Oct 2012 06:20:02 +0000 Subject: [PATCH] fix contains() test when arg is undefined --- enums.js | 6 +++--- enums.spec.js | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/enums.js b/enums.js index 560ae4b..06734fc 100644 --- a/enums.js +++ b/enums.js @@ -6,7 +6,7 @@ }); return target; } - + function Symbol(name, props) { this.name = name; if (props) { @@ -46,10 +46,10 @@ ); } Enum.prototype.contains = function(sym) { - if (! sym instanceof Symbol) return false; + if (!(sym instanceof Symbol)) return false; return this[sym.name] === sym; } exports.Enum = Enum; exports.Symbol = Symbol; }(typeof exports === "undefined" ? this.enums = {} : exports)); -// Explanation of this pattern: http://www.2ality.com/2011/08/universal-modules.html \ No newline at end of file +// Explanation of this pattern: http://www.2ality.com/2011/08/universal-modules.html diff --git a/enums.spec.js b/enums.spec.js index 57d7ba8..59b6646 100644 --- a/enums.spec.js +++ b/enums.spec.js @@ -17,6 +17,7 @@ describe("Enum", function() { var fruit = new enums.Enum("apple", "banana"); expect(color.contains(color.red)).toBeTruthy(); expect(color.contains(fruit.apple)).toBeFalsy(); + expect(color.contains(undefined)).toBeFalsy(); }); });