added options argument to Backbone.Model initialize function

This commit is contained in:
Raimonds Simanovskis
2010-11-03 18:28:40 +02:00
parent 6181445f3e
commit 771b87f17c
2 changed files with 12 additions and 2 deletions

View File

@@ -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.

View File

@@ -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;