documentcloud/backbone — pull request #2557 by matthewwithanm (2013-05-23 04:41:46+00:00)
Title: Separate Attributes Mixin (#2526)

As suggested by @tgriesser, I've implemented the feature I suggested in #2526 (a mixin for adding observable attributes to arbitrary objects). It works just like Backbone.Events, in that it's mixed in with `_.extend`. There's not much new here; just making the related methods usable on non-Models.

```javascript
var object = {};
_.extend(object, Backbone.Attributes);
object.on('change', function(){ alert('changed'); });
object.set('someAttribute', 'value');
```

Or on a view:

```coffeescript
class TinyWidget extends Backbone.View
_.extend @prototype, Backbone.Attributes

widget = new TinyWidget
widget.on 'change:color', -> alert 'color changed!'
widget.set color: '#0000FF'
```