diff --git a/backbone.js b/backbone.js index 4e116dec9..83f7e0d26 100644 --- a/backbone.js +++ b/backbone.js @@ -554,6 +554,7 @@ options || (options = {}); if (options.model) this.model = options.model; if (options.comparator !== void 0) this.comparator = options.comparator; + this.models = []; this._reset(); this.initialize.apply(this, arguments); if (models) this.reset(models, _.extend({silent: true}, options)); @@ -796,7 +797,7 @@ for (var i = 0, l = this.models.length; i < l; i++) { this._removeReference(this.models[i]); } - options.previousModels = this.models; + options.previousModels = this.models.slice(); this._reset(); if (models) this.add(models, _.extend({silent: true}, options)); if (!options.silent) this.trigger('reset', this, options); @@ -849,7 +850,7 @@ // Reset all internal state. Called when the collection is reset. _reset: function() { this.length = 0; - this.models = []; + this.models.length = 0; this._byId = {}; }, diff --git a/test/collection.js b/test/collection.js index 0bca07d94..5dda3235d 100644 --- a/test/collection.js +++ b/test/collection.js @@ -499,7 +499,7 @@ $(document).ready(function() { test("reset", 10, function() { var resetCount = 0; - var models = col.models; + var models = col.models.slice(); col.on('reset', function() { resetCount += 1; }); col.reset([]); equal(resetCount, 1);