Overriding Backbone.Collection.prototype.add

backbone.js, javascript

Solution

Try the following:

var Example = Backbone.Collection.extend({
    add: function(models, options) {
        Backbone.Collection.prototype.add.call(this, models.items, options);
    }
})

Then you can extend all collections from `Example`.

Problem

Is it possible to override the collection.add method globally in backbone like so: ``` Backbone.Collection.prototype._add = Backbone.Collection.prototype.add; Backbone.Collection.prototype.add = function(models, options) { var = newModels = models.items; Backbone.Collection.prototype._add(newModels, options); } ``` The api I'm using ALWAYS contains the actual models one level down for collections. Under `items` and I find myself overriding the `.add` method for all collections. I tried what I have above but it didn't seem to work. Any ideas? Thanks, Luis

Original source