From cd11702167608d5e92fc78b4f7931ca89ff0da29 Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Sat, 23 May 2015 12:29:00 -0400 Subject: [PATCH] Un-golf #changedAttributes --- backbone.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/backbone.js b/backbone.js index 1dfbd9c5..3b60e6fb 100644 --- a/backbone.js +++ b/backbone.js @@ -539,13 +539,14 @@ // determining if there *would be* a change. changedAttributes: function(diff) { if (!diff) return this.hasChanged() ? _.clone(this.changed) : false; - var val, changed = false; var old = this._changing ? this._previousAttributes : this.attributes; + var changed = {}; for (var attr in diff) { - if (_.isEqual(old[attr], (val = diff[attr]))) continue; - (changed || (changed = {}))[attr] = val; + var val = diff[attr]; + if (_.isEqual(old[attr], val)) continue; + changed[attr] = val; } - return changed; + return _.size(changed) ? changed : false; }, // Get the previous value of an attribute, recorded at the time the last