mirror of
https://github.com/jashkenas/backbone.git
synced 2026-01-15 01:47:55 -05:00
Merge pull request #1792 from caseywebdev/reorder-constructor
Fix #1791 reorder constructor so `attributes` is defined for `parse`
This commit is contained in:
@@ -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 = {};
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user