From abdf57c6c574c5d2d50830d054c453d2895a374e Mon Sep 17 00:00:00 2001 From: Eduardo Sorribas Date: Thu, 12 Feb 2015 13:25:38 +0100 Subject: [PATCH] Make the new keyword optional. --- set.js | 1 + test/set-test.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/set.js b/set.js index 8070fd4..fd8e1a0 100644 --- a/set.js +++ b/set.js @@ -43,6 +43,7 @@ var value = true } var Set = function(input){ + if (!(this instanceof Set)) return new Set(input) this._set = unique(input || []) } diff --git a/test/set-test.js b/test/set-test.js index aaf30e0..ee1c103 100644 --- a/test/set-test.js +++ b/test/set-test.js @@ -195,5 +195,21 @@ vows.describe('Set').addBatch({ } } } + + , "Initialized with [0,1,2,3,4] without the new keyword": { + topic: Set([0, 1, 2, 3, 4]) + + , "will be a Set": function(topic){ + assert.instanceOf(topic, Set) + } + + , "is not empty": function(topic){ + assert.isFalse(topic.empty()) + } + + , "contains a 0": function(topic){ + assert.isTrue(topic.contains(0)) + } + } } }).export(module)