After I asked this question and realized that Backbone.Collection
s are strictly for Backbone.Models
, I'm a little disappointed.
What I was hoping for:
Make underscore's methods more object oriented:
_.invoke(myCollection, 'method'); ==> myCollection.invoke('method');
I'll admit, minor difference, yet still it seems nice.
What problems will I run into if I use Backbone.Collection
for non-Backbone.Models
?
Are there any existing implementations, or a simple way to make a generic underscore collection class?
While you can't use a Backbone Collection without using models, I came up with a clever way to mix in underscore into the Array prototype:
Here is an example of how to use the new Array prototypes:
This solution might add more to the Array prototype than is actually useful, but it gets you the bulk of the functions. Another solution would be to only add functions that have an iterator argument, but this is a start for you.