Skip to content

Commit

Permalink
ES6: Map.prototype.clear
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanpenner committed Sep 27, 2014
1 parent f4ea673 commit 11544cc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/ember-metal/lib/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,15 @@ Map.prototype = {
this.keys.forEach(cb);
},

/**
@method clear
*/
clear: function() {
this.keys.clear();
this.values = Object.create(null);
this.size = 0;
},

/**
@method copy
@return {Ember.Map}
Expand Down
24 changes: 24 additions & 0 deletions packages/ember-metal/tests/map_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,30 @@ function testMap(nameAndFunc) {

equal(iteration, 4, 'expected 3 iterations');
});

test("clear", function() {
var iterations = 0;

map.set("a", 1);
map.set("b", 2);
map.set("c", 3);
map.set("d", 4);

equal(map.size, 4);

map.forEach(function() {
iterations++;
});
equal(iterations, 4);

map.clear();
equal(map.size, 0);
iterations = 0;
map.forEach(function() {
iterations++;
});
equal(iterations, 0);
});
}

for (var i = 0; i < varieties.length; i++) {
Expand Down

0 comments on commit 11544cc

Please sign in to comment.