From f329cbffe412c4315ea5aa49b1fd5da5325bcf95 Mon Sep 17 00:00:00 2001 From: Brad Dunbar Date: Wed, 11 Jan 2012 17:37:51 -0500 Subject: [PATCH 1/2] only increment length once --- backbone.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backbone.js b/backbone.js index 485ec30a..0581cc7b 100644 --- a/backbone.js +++ b/backbone.js @@ -429,8 +429,8 @@ this._byCid[model.cid] = model; if (hasId) this._byId[model.id] = model; model.bind('all', this._onModelEvent, this); - this.length++; } + this.length += l; i = options.at != null ? options.at : this.models.length; splice.apply(this.models, [i, 0].concat(models)); if (this.comparator) this.sort({silent: true}); From 4dd506c3d466983c1247d44df2b78db3b981483b Mon Sep 17 00:00:00 2001 From: Brad Dunbar Date: Wed, 11 Jan 2012 18:25:17 -0500 Subject: [PATCH 2/2] more descriptive variable name --- backbone.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backbone.js b/backbone.js index 0581cc7b..f72eb2fb 100644 --- a/backbone.js +++ b/backbone.js @@ -416,11 +416,11 @@ // Add a model, or list of models to the set. Pass **silent** to avoid // firing the `added` event for every new model. add : function(models, options) { - var i, l; + var i, length; options || (options = {}); if (!_.isArray(models)) models = [models]; models = slice.call(models); - for (i = 0, l = models.length; i < l; i++) { + for (i = 0, length = models.length; i < length; i++) { var model = models[i] = this._prepareModel(models[i], options); var hasId = model.id != null; if (this._byCid[model.cid] || (hasId && this._byId[model.id])) { @@ -430,12 +430,12 @@ if (hasId) this._byId[model.id] = model; model.bind('all', this._onModelEvent, this); } - this.length += l; + this.length += length; i = options.at != null ? options.at : this.models.length; splice.apply(this.models, [i, 0].concat(models)); if (this.comparator) this.sort({silent: true}); if (options.silent) return this; - for (i = 0; i < l; i++) { + for (i = 0; i < length; i++) { models[i].trigger('add', models[i], this, options); } return this;