Skip to content

Commit c5d1c28

Browse files
committed
Yield the model to the sortBy callback.
1 parent 944c2da commit c5d1c28

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/collection.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
Collection.prototype.sortBy = function(attribute_or_func) {
121121
var is_func = Model.Utils.isFunction(attribute_or_func)
122122
var extract = function(model) {
123-
return attribute_or_func.call(model)
123+
return attribute_or_func.call(model, model)
124124
}
125125

126126
return this.sort(function(a, b) {

test/tests/collection_test.js

+18
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,24 @@ test("#sort, #sortBy", function() {
111111
ok(sorted.at(0) === a)
112112
ok(sorted.at(1) === b)
113113
ok(sorted.at(2) === c)
114+
115+
sorted = collection.sortBy(function() {
116+
return this.get("title")
117+
})
118+
119+
ok(sorted instanceof Model.Collection, "returns another Collection")
120+
ok(sorted.at(0) === a)
121+
ok(sorted.at(1) === b)
122+
ok(sorted.at(2) === c)
123+
124+
sorted = collection.sortBy(function(post) {
125+
return post.get("title")
126+
})
127+
128+
ok(sorted instanceof Model.Collection, "returns another Collection")
129+
ok(sorted.at(0) === a)
130+
ok(sorted.at(1) === b)
131+
ok(sorted.at(2) === c)
114132
})
115133

116134
test("#detect", function() {

0 commit comments

Comments
 (0)