Skip to content

Commit

Permalink
Issue jashkenas#132 ... initial _changed after new with attributes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed Dec 10, 2010
1 parent 81cd0cf commit 53ae5b5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions backbone.js
Expand Up @@ -121,6 +121,7 @@
this._escapedAttributes = {};
this.cid = _.uniqueId('c');
this.set(attributes, {silent : true});
this._changed = false;
this._previousAttributes = _.clone(this.attributes);
if (options && options.collection) this.collection = options.collection;
this.initialize(attributes, options);
Expand Down
9 changes: 9 additions & 0 deletions test/model.js
Expand Up @@ -204,6 +204,15 @@ $(document).ready(function() {
equals(value, 'Ms. Sue');
});

test("Model: change after initialize", function () {
var changed = 0;
var attrs = {id: 1, label: 'c'};
var obj = new Backbone.Model(attrs);
obj.bind('change', function() { changed += 1; });
obj.set(attrs);
equals(changed, 0);
});

test("Model: save within change event", function () {
var model = new Backbone.Model({firstName : "Taylor", lastName: "Swift"});
model.bind('change', function () {
Expand Down

0 comments on commit 53ae5b5

Please sign in to comment.