Skip to content

Commit

Permalink
Fixes jashkenas#2724, leak with non-specific calls to stopListening.
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed Sep 11, 2013
1 parent 9e8fca0 commit c198270
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions backbone.js
Expand Up @@ -155,11 +155,12 @@
var listeningTo = this._listeningTo;
if (!listeningTo) return this;
var remove = !name && !callback;
if (typeof name === 'object') callback = this;
if (!callback && typeof name === 'object') callback = this;
if (obj) (listeningTo = {})[obj._listenId] = obj;
for (var id in listeningTo) {
listeningTo[id].off(name, callback, this);
if (remove) delete this._listeningTo[id];
obj = listeningTo[id];
obj.off(name, callback, this);
if (remove || _.isEmpty(obj._events)) delete this._listeningTo[id];
}
return this;
}
Expand Down Expand Up @@ -219,7 +220,7 @@
var listeningTo = this._listeningTo || (this._listeningTo = {});
var id = obj._listenId || (obj._listenId = _.uniqueId('l'));
listeningTo[id] = obj;
if (typeof name === 'object') callback = this;
if (!callback && typeof name === 'object') callback = this;
obj[implementation](name, callback, this);
return this;
};
Expand Down

0 comments on commit c198270

Please sign in to comment.