Permalink
Browse files

Merge pull request #842 from braddunbar/hasChanged-comparison

hasChanged/set should use the same comparison
  • Loading branch information...
2 parents d06e8a6 + 934aba4 commit 060da2b991f39051c5851f6761be31a66f0cff77 @jashkenas jashkenas committed Jan 6, 2012
Showing with 14 additions and 1 deletion.
  1. +1 −1 backbone.js
  2. +13 −0 test/model.js
View
@@ -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
@@ -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);
+ });
+
});

0 comments on commit 060da2b

Please sign in to comment.