I follow an example using require.js and backbone.js. In this example, the model does not use new when returned. In my code I have to use new , otherwise I get an error message:
Uncaught TypeError: Object function (){a.apply(this,arguments)} has no method 'toJSON'
Does not work:
define([ 'underscore', 'backbone' ], function(_, Backbone) { var personModel = Backbone.Model.extend({ defaults: { conversations: 'No Conversations' }, initialize: function(){ } }); return personModel; });
Works:
define([ 'underscore', 'backbone' ], function(_, Backbone) { var personModel = Backbone.Model.extend({ defaults: { conversations: 'No Conversations' }, initialize: function(){ } }); return new personModel; });
Does anyone know why?
source share