Skip to content

Commit

Permalink
Invert the for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
jridgewell authored and akre54 committed Nov 3, 2014
1 parent e7126ec commit 711b658
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,18 +241,14 @@
};

Events.listenToOnce = function(obj, name, callback) {
this.listenTo(obj, name, callback);

var onces = name;
if (typeof onces !== 'object') {
onces = {};
onces[name] = callback;
}
for (var event in onces) {
callback = _.partial(this.stopListening, obj, event, onces[event]);
callback._callback = onces[event];
this.listenTo(obj, event, callback);
if (typeof name === 'object') {
for (var event in name) this.listenToOnce(obj, event, name[event]);
return this;
}
var once = _.partial(this.stopListening, obj, name, callback);
once._callback = callback;
this.listenTo(obj, name, callback);
this.listenTo(obj, name, once);
return this;
};

Expand Down

0 comments on commit 711b658

Please sign in to comment.