Skip to content

Instantly share code, notes, and snippets.

@s4y
Created July 19, 2011 23:12
Show Gist options
  • Save s4y/1093975 to your computer and use it in GitHub Desktop.
Save s4y/1093975 to your computer and use it in GitHub Desktop.
Backbone.Collection subtype which uses native-style comparators
var NativeSortingCollection = Backbone.Collection.extend({
sortedIndex: function(candidate, comparator){
var i = 0;
while (i < this.models.length && comparator(this.models[i], candidate) <= 0) {
i++;
}
return i;
},
sortBy: function(comparator){
return this.models.sort(comparator);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment