remove: function(models) { // If given a single item, wrap it in an array if (! _.isArray(models)) { models = [ models ]; } // Store the removed models here so we can give them to the remove event var removed = [ ]; // Filter out the models in the collection that match those given this.models = _.rejectInPlace(this.models, function(model) { return !! _.find(models, function(matchAgainst) { return model.is(matchAgainst) && removed.push(model); }); }); // Was anything actually removed? if (removed.length) { this.emit('remove', removed); } return this; },
rejectInPlace: function(func) { _.rejectInPlace(this.models, func); return this; },