I'm .clone() -ing a collection so that I can use a splice loop on it and not interfere with the original. Are the models in cloned array originals or copies?
What I need is a copy of the array with the original models in it.
Thanks for any info!
You will get the same models as the source collection wrapped in a new collection of the same type.
Here is the implementation of collection.clone:
clone: function() {
return new this.constructor(this.models);
},
Or if you prefer a deep clone, override Backbone.Collection.clone
clone: function(deep) {
if(deep) {
return new this.constructor(_.map(this.models, function(m) { return m.clone(); }));
}else{
return Backbone.Collection.prototype.clone();
}
}
http://jsfiddle.net/puleos/9bk4d/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With