where
isn't the only method that returns an Array
. where
returns a new Array
because you definitely don't want it mutating your existing Collection
automatically. Also, many times you may want the result in Array
form.
For whatever reason, the BB devs decided that it was better to return a new Array
rather than a new Collection
. One thought could be that, perhaps the returned data would be used in a different type of Collection
. Another reason could be so that you always know what is returned from one of these methods. 2+ types of collections will ALWAYS return Arrays
from these types of methods rather than having to try and inspect via instanceof
or something else that isn't very reliable.
Edit
In addition, you COULD make your collections behave in a manner where you return new Collections
. Create a base Collection to do something like this:
// Override the following methods
var override = ["where","find",...];
var collectionProto = Backbone.Collection.prototype;
BaseCollection = Backbone.Collection.extend({});
for (var key in collectionProto) {
if (collectionProto.hasOwnProperty(key) && override.indexOf(key) > -1) {
BaseCollection.prototype[key] = function () {
return new this.constructor(collectionProto[key].apply(this, arguments);
};
}
}
Instead over extending off Backbone.Collection, extend off BaseCollection.