documentcloud/backbone — pull request #2065 by jdkanani (2013-01-03 13:43:08+00:00)
Title: Use `toJSON` in Model `clone` to take advantage of nested model and collection

This change doesn't give much significant results as long as you are not using nested model and collection.
It will add more value when you just override `toJSON` method, and `clone` method will start behaving accordingly.

```javascript
var Mailbox = Backbone.Model.extend({
initialize: function (attributes, options) {
this.personalInfo = new PersonalInfo(attributes.personalInfo);
this.messages = new Messages(attributes.messages);
},
toJSON: function () {
return _.extends(_.clone(this.attributes), {
personalInfo: this.get('personalInfo').toJSON(),
messages: this.get('messages').toJSON()
});
}
});
```
`new Mailbox(data).clone()` will have following raw data :

```javascript
{
personalInfo : {
name: 'John Doe'
...
},
messages : [
{
from: 'backbonejs@gmail.com',
body: 'hello'
}
...
]
...
}
```