From 1f3d25e89be343f065914c03630e3f130cf54c36 Mon Sep 17 00:00:00 2001 From: Welling Guzman Date: Fri, 16 Jun 2017 14:27:19 -0400 Subject: [PATCH] avoid using _.each on set method Models with an attributed named 'length' will make this each work as an array unexpectedly --- backbone.trackit.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/backbone.trackit.js b/backbone.trackit.js index cb1354e..84304b4 100644 --- a/backbone.trackit.js +++ b/backbone.trackit.js @@ -159,12 +159,13 @@ ret = oldSet.call(this, attrs, options); if (this._trackingChanges && !options.silent && !options.trackit_silent) { - _.each(attrs, _.bind(function(val, key) { - if (_.isEqual(this._originalAttrs[key], val)) - delete this._unsavedChanges[key]; - else - this._unsavedChanges[key] = val; - }, this)); + for (key in attrs) { + val = attrs[key]; + if (_.isEqual(this._originalAttrs[key], val)) + delete this._unsavedChanges[key]; + else + this._unsavedChanges[key] = val; + } this._triggerUnsavedChanges(); } return ret;