Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #842 from braddunbar/hasChanged-comparison

hasChanged/set should use the same comparison
  • Loading branch information...
commit 060da2b991f39051c5851f6761be31a66f0cff77 2 parents d06e8a6 + 934aba4
@jashkenas jashkenas authored
Showing with 14 additions and 1 deletion.
  1. +1 −1  backbone.js
  2. +13 −0 test/model.js
View
2  backbone.js
@@ -324,7 +324,7 @@
// Determine if the model has changed since the last `"change"` event.
// If you specify an attribute name, determine if that attribute has changed.
hasChanged : function(attr) {
- if (attr) return this._previousAttributes[attr] != this.attributes[attr];
+ if (attr) return !_.isEqual(this._previousAttributes[attr], this.attributes[attr]);
return this._changed;
},
View
13 test/model.js
@@ -492,4 +492,17 @@ $(document).ready(function() {
equal(counter, 1, 'change is only triggered once');
});
+ test("hasChanged/set should use same comparison", function() {
+ expect(2);
+ var changed = 0, model = new Backbone.Model({a: null});
+ model.bind('change', function() {
+ ok(this.hasChanged('a'));
+ })
+ .bind('change:a', function() {
+ changed++;
+ })
+ .set({a: undefined});
+ equal(changed, 1);
+ });
+
});
Please sign in to comment.
Something went wrong with that request. Please try again.