documentcloud/backbone — pull request #811 by jonasschneider (2011-12-23 20:15:08+00:00)
Title: Unbind callbacks with a given context

Just want to find out whether this finds approval. If so, I will rebase and add specs.

Current behaviour:
Imagine two instances of a `Listener` class. They each bind their `fire` method to an event of an object, assume it's the same for both listeners:

object.bind('someEvent', this.fire, this)

Now one of the listeners gets removed for some reason. It unbinds:

object.unbind('someEvent', this.fire)

But actually, the other listener is also unbound, because the `callback` has a value of `Listener.prototype.fire` for both listeners, only the `context` differs.

This commit adds the ability to unbind only the callbacks that have a specified context, so that listeners can be unbound without affecting others. This would give `unbind` the same signature as `bind`, allowing for:

object.unbind('someEvent', this.fire, this)