documentcloud/backbone — pull request #1601 by sebslomski (2012-08-30 18:07:51+00:00)
Title: Model.get should return a clone of the requested attribute, not its reference

``
>>> var m = new Backbone.Model();
>>> m.on('change:foo', function() { console.log('foo changed'); });
>>> m.set('foo', ['bar', 'baz']);
"foo changed"
>>> var x = m.get('foo');
>>> x.push('foobar');
>>> m.set('foo', x);
``javascript

The last command should trigger a ``change`` event, but it doesn't as ``x`` is a reference to ``m.attributes.foo``.
This means the last ``m.set('foo', x);`` is not necessary as ``m.attributes.foo`` is already ``['bar', 'baz', 'foobar']`` because it is a reference. This is evil.

The fix is to return a cloned version of ``foo`` in ``Model.get``.