What is the purpose of the options for the models?


In the Backbone API for Model

the example only sets the attributes as an example. As an optional second parameter you can set options.

I can't find anything in the API that explains this. Also the source code does not make complete sense to me.

var Model = Backbone.Model = function(attributes, options) {
var attrs = attributes || {};
options || (options = {});
this.cid = _.uniqueId('c');
this.attributes = {};
if (options.collection) this.collection = options.collection;
if (options.parse) attrs = this.parse(attrs, options) || {};
attrs = _.defaults({}, attrs, _.result(this, 'defaults'));
this.set(attrs, options);
this.changed = {};
this.initialize.apply(this, arguments);

Are they only for setting collection and parse? Why are they broken off an made separate from attributes?

On the top of my head I can see 2 reasons:

  1. options is not data everyting going to attributes can be accessed using .get(attrName)
  2. options is also send though to the .set method.

And we havnt even talked about what is going on in the initialize method. You can use this to tons of cool stuff.