I have been fighting with this problem for hours. I can’t seem to figure out why my code had worked and now is not!
I’m building a fairly complex application with Backbone and Marionette on requirejs and I’m new to all of these libraries so it is a little confusing.
I’m getting the error
Uncaught TypeError: Object [object Object] has no method 'apply'
And I can’t seem to figure out what happened or why my app does not work now no matter what code I seem to comment out.
ANY help to point me in the right direction?
I found the problem. I had been going through my code and “optimizing” (so I thought) some of the redundancies.
Instead of this:
I had changed a bunch of code to look like this:
Not a problem right? Mostly.
I was ALSO using a nifty trick I read about on another post about getting singleton functionality from require.js modules by returning an instantiated model! Cool… mostly.
I had this:
and it worked great!
Then I got cocky…
and I started getting my
has no method 'apply'error.It took me the better part of 2 days and lots of frustration to track down the problem and I finally got the answer from this post:
new Backbone.Model() vs Backbone.Model.extend()
It explains nicely how you can instantiate Backbone.Model but Backbone.Model.extend merely provides you with a constructor that you can THEN use to instantiate a custom Backbone.Model object.
I hope this saves someone the pain I just went through.