documentcloud/backbone — Issue #682: Unbinding events by callback context
Author: smithclay
Created: 2011-10-20 18:17:22+00:00
State: open

Let's say I have a model, and two views listening for "change" events on the same model.

```javascript
View1 {
initialize: function() {
this.model.bind("change", this.modelChangedView1);
},
modelChangedView1: function() {
}
}

View2 {
initialize: function() {
this.model.bind("change", this.modelChangedView2);
},
modelChangedView2: function() {
}
}
```

Then, View2 is removed from the page `view2.remove()`. As I currently understand it, `modelChangedView2` will still fire on all model `change` events. If I call `model.unbind("change")` or `model.unbind()`, all `change` event bindings on that model will be removed: I'll lose both `modelChangedView1` and `modelChangedView2` callbacks.

It seems to me like:
* When a view is removed, all bindings that refer to that view should be cleaned up somehow.
* Or, it should be possible somehow to `.unbind()` by the context of the callback. Something like `model.unbind("change", view2)`?
* Or, it's entirely possible that multiple views listening for "change" events on a model is just a bad idea in general. But any guidance on the best practice (creative event namespacing?) would be appreciated.