Skip to content

Commit

Permalink
fix Constructor Map requires 'new' in MultiMap
Browse files Browse the repository at this point in the history
  • Loading branch information
hthetiot committed Jul 11, 2018
1 parent 60c3c2e commit ecfa4b5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions multi-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

var Map = require("./map").Map;


module.exports = MultiMap;
function MultiMap(values, bucket, equals, hash) {
if (!(this instanceof MultiMap)) {
return new MultiMap(values, bucket, equals, hash);
}
this.bucket = bucket || this.bucket;
Map.call(this, values, equals, hash, function getDefault(key) {
new (Function.prototype.bind.call(Map, this, values, equals, hash, function getDefault(key) {
var bucket = this.bucket(key);
Map.prototype.set.call(this, key, bucket);
return bucket;
});
}));
}

MultiMap.MultiMap = MultiMap; // hack so require("multi-map").MultiMap will work in MontageJS
Expand Down
1 change: 1 addition & 0 deletions test/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = require("montage-testing").run(require, [
"spec/lru-map-spec",
"spec/lru-set-spec",
"spec/map-spec",
"spec/multi-map-spec",
"spec/regexp-spec",
"spec/set-spec",
"spec/shim-array-spec",
Expand Down
7 changes: 7 additions & 0 deletions test/spec/multi-map-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

module.exports = describeMultiMap;
function describeMultiMap(MultiMap, values) {
it("should be constructable", function () {
var accountsMultiMap = new MultiMap()
});
};

0 comments on commit ecfa4b5

Please sign in to comment.