Skip to content

Commit c9ea5a7

Browse files
committed
Allow chaining in map.set and set.add.
1 parent c083d6b commit c9ea5a7

5 files changed

Lines changed: 8 additions & 9 deletions

File tree

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ entries({foo: 42, bar: true}); // [{key: "foo", value: 42}, {key: "bar", value:
245245
Like [ES6 Maps](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map), but with a few differences:
246246

247247
* Keys are coerced to strings.
248-
* [map.set](#map_set) returns the new value, not the map itself.
249248
* [map.each](#map_each), not [map.forEach](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach). (Also, no *thisArg*.)
250249
* [map.remove](#map_remove), not [map.delete](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete).
251250
* [map.entries](#map_entries) returns an array of {key, value} objects, not an iterator of [key, value].
@@ -313,7 +312,6 @@ Returns the number of entries in this map.
313312
Like [ES6 Sets](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set), but with a few differences:
314313

315314
* Values are coerced to strings.
316-
* [set.add](#set_add) returns the new value, not the set itself.
317315
* [set.each](#set_each), not [set.forEach](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach). (Also, no *thisArg*.)
318316
* [set.remove](#set_remove), not [set.delete](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/delete).
319317
* [set.size](#set_size) is a method, not a [property](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/size); also, there’s [set.empty](#set_empty).

src/map.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ Map.prototype = map.prototype = {
1010
return this[prefix + key];
1111
},
1212
set: function(key, value) {
13-
return this[prefix + key] = value;
13+
this[prefix + key] = value;
14+
return this;
1415
},
1516
remove: function(key) {
1617
var property = prefix + key;

src/set.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Set.prototype = set.prototype = {
99
add: function(value) {
1010
value += "";
1111
this[prefix + value] = true;
12-
return value;
12+
return this;
1313
},
1414
remove: proto.remove,
1515
clear: proto.clear,

test/map-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,9 @@ tape("map.get(key) returns undefined for missing keys", function(test) {
305305
test.end()
306306
});
307307

308-
tape("map.set(key, value) returns the set value", function(test) {
308+
tape("map.set(key, value) returns the map", function(test) {
309309
var m = arrays.map();
310-
test.equal(m.set("foo", 42), 42);
310+
test.equal(m.set("foo", 42), m);
311311
test.end();
312312
});
313313

test/set-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,10 @@ tape("set.has(value) returns undefined for missing values", function(test) {
193193
test.end();
194194
});
195195

196-
tape("set.add(value) returns the set value, coerced to a string", function(test) {
196+
tape("set.add(value) returns the set", function(test) {
197197
var s = arrays.set();
198-
test.equal(s.add("foo"), "foo");
199-
test.strictEqual(s.add(2), "2");
198+
test.equal(s.add("foo"), s);
199+
test.equal(s.add(2), s);
200200
test.deepEqual(s.values().sort(), ["2", "foo"]);
201201
test.end();
202202
});

0 commit comments

Comments
 (0)