Skip to content

Commit

Permalink
Merge pull request jashkenas#3281 from jisaacks/master
Browse files Browse the repository at this point in the history
Allow Collection.at to accept negative indexes
  • Loading branch information
akre54 committed Sep 25, 2014
2 parents c349965 + bcd7549 commit 4927b6e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,7 @@

// Get the model at the given index.
at: function(index) {
if (index < 0) index += this.length;
return this.models[index];
},

Expand Down
3 changes: 2 additions & 1 deletion test/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@
equal(col.get(101).get('name'), 'dalmatians');
});

test("at", 1, function() {
test("at", 2, function() {
equal(col.at(2), c);
equal(col.at(-2), c);
});

test("pluck", 1, function() {
Expand Down

0 comments on commit 4927b6e

Please sign in to comment.