mirror of
https://github.com/jashkenas/backbone.git
synced 2026-01-22 13:28:22 -05:00
Merge pull request #1342 from caseywebdev/master
Allow Collection to receive falsy `comparator` to override default
This commit is contained in:
@@ -548,7 +548,7 @@
|
||||
var Collection = Backbone.Collection = function(models, options) {
|
||||
options || (options = {});
|
||||
if (options.model) this.model = options.model;
|
||||
if (options.comparator) this.comparator = options.comparator;
|
||||
if (options.comparator !== undefined) this.comparator = options.comparator;
|
||||
this._reset();
|
||||
this.initialize.apply(this, arguments);
|
||||
if (models) this.reset(models, {silent: true, parse: options.parse});
|
||||
|
||||
@@ -606,4 +606,18 @@ $(document).ready(function() {
|
||||
ok(!collection.get('undefined'));
|
||||
});
|
||||
|
||||
test("Collection: falsy comparator", function(){
|
||||
var Col = Backbone.Collection.extend({
|
||||
comparator: function(model){ return model.id; }
|
||||
});
|
||||
var col = new Col
|
||||
var colFalse = new Col(null, {comparator: false});
|
||||
var colNull = new Col(null, {comparator: null});
|
||||
var colUndefined = new Col(null, {comparator: undefined});
|
||||
ok(col.comparator);
|
||||
ok(!colFalse.comparator);
|
||||
ok(!colNull.comparator);
|
||||
ok(colUndefined.comparator);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user