Firstly, apologies for the title - if anyone has a better version after reading the question, please edit or ask me to.
I have extended the core Backbone Collection object with a 'where' method that allows me to perform an _.select on the models within the collection. Currently this returns a new vanilla Collection object containing the models. What I want is for the method to return a Collection object of the same type as I am calling ...
Backbone.Collection.prototype.where = function(a) { var execute = function(item) { ... }; return new Backbone.Collection(this.select(execute)); }; var Accounts = Backbone.Collection.extend({...})
What I want, at the return statement is to be returning a new Account collection. But I don't want to have to define or extend this method in each collection I extend. Something like the following pseudo code:
return new instanceof this(this.select(execute));
Make sense?