166
rated 0 times
[
173]
[
7]
/ answers: 1 / hits: 16878
/ 12 Years ago, wed, april 18, 2012, 12:00:00
When you override backbone sync, both model/collection .save()/fetch() uses the same backbone sync method, so what is the best way to check if what Backbone.sync recieves is a model or a collection of models?
As an example:
Backbone.sync = function(method, model, options){
//Model here can be both a collection or a single model so
if(model.isModel()) // there is no isModel or isCollection method
}
I suppose I am looking for a safe best practice, I could of course check for certain attributes or methods that only a model or a collection have, but it seems hackish, shouldn't there be a better obvious way? And there probably is I just couldn't find it.
Thanks!
More From » backbone.js