Issue #2 -- each now calls iterator with (value, key, list) when iterating over javascript objects

This commit is contained in:
Jeremy Ashkenas
2009-10-29 10:46:53 -04:00
parent 8e7b8d2dea
commit 42637b5880
3 changed files with 18 additions and 17 deletions

View File

@@ -26,7 +26,7 @@ $(document).ready(function() {
answers = [];
var obj = {one : 1, two : 2, three : 3};
obj.constructor.prototype.four = 4;
_.each(obj, function(pair){ answers.push(pair.key); });
_.each(obj, function(value, key){ answers.push(key); });
equals(answers.join(", "), 'one, two, three', 'iterating over objects works, and ignores the object prototype.');
delete obj.constructor.prototype.four;
@@ -136,7 +136,7 @@ $(document).ready(function() {
ok(_.isArray(_.toArray(arguments)), 'arguments object converted into array');
var numbers = _.toArray({one : 1, two : 2, three : 3});
equals(_.pluck(numbers, '0').join(', '), 'one, two, three', 'object flattened into array');
equals(numbers.join(', '), '1, 2, 3', 'object flattened into array');
});
test('collections: size', function() {