I update a Backbone collection from array of bare objects by using reset
:
const collection = new Backbone.Collection();
// ...
const switches = [
{ color: "red", on: false },
{ color: "green", on: false },
{ color: "blue", on: true }
];
collection.reset(switches);
Now there are 3 models in my collection. I want them to have toggle()
method:
toggle: function() {
this.save({ on: !this.get("on") })
}
How can I add it?