I have a code:
Application = function() {
Application.prototype.currentQuote.collection.fetch();
};
Application.prototype = {}
Application.prototype.currentQuote = {};
Application.prototype.currentQuote.model = new (Backbone.Model.extend({
defaults: {
products: []
}
}))();
Application.prototype.currentQuote.collection = new (Backbone.Collection.extend({
model: Application.prototype.currentQuote.model,
url: 'test.json'
}))();
App = new Application();
But, when collection is fetched, i get “Uncaught TypeError: object is not a function” error.
I dont understand why, and what i can fix it?
You can see test case here: https://dl.dropbox.com/u/15806777/development/bb/index.html
Thanks!
I’d guess that your problem is right here:
A collection’s
modelis:So the
modelshould be something that comes fromBackbone.Model.extend({...})(i.e. “class”) rather than something that comes fromnew (Backbone.Model.extend({...}))(i.e. a model instance). When you ask a collection to create some models (through the constructor call,fetch,add, …), the collection needs something that it can usenewon and you can’tnew model_instancebecause thenewoperator needs a constructor function:That’s where your “Uncaught TypeError: object is not a function” error comes from.
You’ll need something like this: