Given the following snippet:
var m = new Backbone.Model({
name: 'joshua'
});
m.set('name', 'something else');
If I now call m.hasChanged()
or m.hasChanged('name')
I get false
. Why? My understanding is that both of these should return true
.
m.changedAttributes()
also returns false.
Here is a fiddle that illustrates what I'm doing, and expecting: http://jsfiddle.net/9cvVv/88/
EDIT: It seems that unless you pass { silent: true; }
to the set()
method then it will fire the change
event on your model which clears out the changedAttributes()
, etc. Essentially these properties only track changes since the last time the change
event was triggered.
I read that in the documentation but didn't really understand it at first.
This doesn't seem very useful to me. I would appreciate any explanation of why this works the way it does and the best way to achieve the result I want. (Passing around {silent: true; }
and giving up usage of the change
event seems like a waste.)