QuickCollection (and possibly other constructors) break Backbone prototype chain
Closed this issue · 2 comments
Note the following code sample:
var c = new Backbone.Conduit.QuickCollection;
c instanceof Backbone.Collection; // false
I believe this is due to the prototype established on line 28 of QuickCollection.js.
Note the easiest work-around here is to use the Backbone.Conduit.haul.mixin(...)
instead of extends Backbone.Conduit.QuickCollection
directly. See here:
http://conduit.wagener.org/docs/QuickCollection/extendormixin.html
This is unfortunately the intended behavior. The Backbone.Collection
constructor does some unfortunate things performance-wise when you provide models. I.e. this will not perform well:
var myData = [ {}, {}, {}, ...]; // Assume it is 500K items
var myCollection = new Backbone.Collection(myData);
See the annotated source code for what it does. The calling of this.reset(models, ...)
is what we avoid by breaking the inheritance chain.
I'm open for changing the behavior to work the other way, but I think the work-around (i.e. using Backbone.Conduit.haul.mixin(...)
) is reasonable if you really need to consider your collection an instance of Backbone.Collection
. Any feedback on this tradeoff would be welcome!
Closing this, as it works as designed.