I have a collection of Backbone models like so:
window.Message = Backbone.Model.extend({});
window.MessageCollect = Backbone.Collection.extend({ model: Message, url: '/messages'});
Why do I have to instantiate a new collection in order to call create()? If I call create() on MessageCollect, I get a no method error.
window.Messages = new MessageCollect;
function makeMessage(){ Messages.create({title:'first message', sender:user_name}); }
//ok
function makeMessageTwo(){ MessageCollect.create({title:'first message', sender:user_name}); }
//Object function (){ parent.apply(this, arguments); } has no method 'create'
Because Backbone.Collection – is a class, not an instance. When you call Backbone.Collection.extend you extend base class, you do not create new instance.
Collection.create() – method to create new model in collection INSTANCE. When you don’t have instance, how can you append new models into it?