Skip to content

Commit

Permalink
Merge pull request jashkenas#1792 from caseywebdev/reorder-constructor
Browse files Browse the repository at this point in the history
Fix jashkenas#1791 reorder constructor so `attributes` is defined for `parse`
  • Loading branch information
Sam Breed committed Nov 2, 2012
2 parents 34cb42d + 7909341 commit aeaf2ee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 4 additions & 4 deletions backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,16 @@
var defaults;
var attrs = attributes || {};
if (options && options.collection) this.collection = options.collection;
if (options && options.parse) attrs = this.parse(attrs);
if (defaults = _.result(this, 'defaults')) {
attrs = _.extend({}, defaults, attrs);
}
this.attributes = {};
this._escapedAttributes = {};
this.cid = _.uniqueId('c');
this.changed = {};
this._changes = {};
this._pending = {};
if (options && options.parse) attrs = this.parse(attrs);
if (defaults = _.result(this, 'defaults')) {
attrs = _.extend({}, defaults, attrs);
}
this.set(attrs, {silent: true});
// Reset change tracking.
this.changed = {};
Expand Down
8 changes: 8 additions & 0 deletions test/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -889,4 +889,12 @@ $(document).ready(function() {
deepEqual(changes, ['a',1,'item']);
});

test("#1791 - `attributes` is available for `parse`", function() {
var Model = Backbone.Model.extend({
parse: function() { this.has('a'); } // shouldn't throw an error
});
var model = new Model(null, {parse: true});
expect(0);
});

});

0 comments on commit aeaf2ee

Please sign in to comment.