Merge pull request #2386 from tgriesser/doc-custom-constructor

Adding custom constructor example code.
This commit is contained in:
Jeremy Ashkenas
2013-03-18 20:35:59 -07:00

View File

@@ -956,6 +956,19 @@ new Book({
you to replace the actual constructor function for your model.
</p>
<pre>
var Library = Backbone.Model.extend({
constructor: function() {
this.books = new Books();
Backbone.Model.apply(this, arguments);
},
parse: function(data, options) {
this.books.reset(data.books);
return data.library;
}
});
</pre>
<p>
If you pass a <tt>{collection: ...}</tt> as the <b>options</b>, the model
gains a <tt>collection</tt> property that will be used to indicate which