Reputation: 261
I am working on a project using the following namespacing scheme:
var abc = {};
abc.models = {};
abc.views = {};
abc.models.Collection = Backbone.Collection.extend({});
When I seek to create a new collection I receive the following error
var collection = new abc.models.Collection({this:"that"});
TypeError: Object #<Object> has no method '_reset'
when I moved the constructor to abc.Collection
the error stopped and everything started working as needed.
Can someone please help me understand why this is?
I should also add that this is part of a multi-file application where each file is wrapped with the following:
(function($, abc){
//module contents here
}(jQuery, abc));
Upvotes: 2
Views: 814
Reputation: 24324
this works:
var abc = {};
abc.models = {};
abc.views = {};
abc.models.Collection = Backbone.Collection.extend({});
var collection = new abc.models.Collection([], {});
whereas this trips with Uncaught TypeError: Object #<Object> has no method '_reset'
:
var abc = {};
abc.models = {};
abc.views = {};
abc.models.Collection = Backbone.Collection.extend({});
var collection = abc.models.Collection([], {});
The difference is not calling the constructor with new
.
Upvotes: 3
Reputation: 302
The first argument to a new Backbone Collection is an array of models and then a hash of options. Are you trying to pass in an array of models, if not then pass in the empty array: []
Upvotes: 0