documentcloud/backbone — pull request #1092 by afeld (2012-03-12 07:17:32+00:00)
Title: Refactor Backbone.Model to not access `attributes` property directly, and add `getData()` method

*Most* `Backbone.Model` methods no longer access `attributes` directly. Instead, most core methods now use `get()` or new `getData()` method. Using `get()` internally is beneficial to users wanting or plugin developers wanting to override the method, because other methods that rely on it now reflect what the user would expect. For example:

```javascript
var Person = Backbone.Model.extend({
get: function(attr) {
if (attr === 'fullName') {
return this.get('firstName') + ' ' + this.get('lastName');
} else {
return Backbone.Model.prototype.get.apply(this, arguments);
}
}
});

var user = new Person({
firstName: 'John',
lastName: 'Smith'
});

alert(user.has('fullName')); // would have returned 'false' before
```

The above example is somewhat unusual for most use cases, but the change is far more relevant for extensions to Models like [Backbone-Nested](http://afeld.github.com/backbone-nested/) and [Ligament](https://github.com/dbrady/ligament.js) because it reduces the number of methods that I- \*ahem\*, _they_ - need to override to provide expected behavior for methods like `has()` and `escape()`.

In the same way, `getData()` now provides an alternative to cloning the `attributes` directly, but still leaves `toJSON()` available to the user to modify for custom serialization/persistence.