mirror of
https://github.com/jashkenas/backbone.git
synced 2026-01-23 05:48:10 -05:00
added options argument to Backbone.Model initialize function
This commit is contained in:
@@ -107,12 +107,12 @@
|
||||
|
||||
// Create a new model, with defined attributes. A client id (`cid`)
|
||||
// is automatically generated and assigned for you.
|
||||
Backbone.Model = function(attributes) {
|
||||
Backbone.Model = function(attributes, options) {
|
||||
this.attributes = {};
|
||||
this.cid = _.uniqueId('c');
|
||||
this.set(attributes || {}, {silent : true});
|
||||
this._previousAttributes = _.clone(this.attributes);
|
||||
if (this.initialize) this.initialize(attributes);
|
||||
if (this.initialize) this.initialize(attributes, options);
|
||||
};
|
||||
|
||||
// Attach all inheritable methods to the Model prototype.
|
||||
|
||||
@@ -38,6 +38,16 @@ $(document).ready(function() {
|
||||
equals(model.one, 1);
|
||||
});
|
||||
|
||||
test("Model: initialize with attributes and options", function() {
|
||||
var Model = Backbone.Model.extend({
|
||||
initialize: function(attributes, options) {
|
||||
this.one = options.one;
|
||||
}
|
||||
});
|
||||
var model = new Model({}, {one: 1});
|
||||
equals(model.one, 1);
|
||||
});
|
||||
|
||||
test("Model: url", function() {
|
||||
equals(doc.url(), '/collection/1-the-tempest');
|
||||
doc.collection = null;
|
||||
|
||||
Reference in New Issue
Block a user