TypeError: Backbone.$ is undefined

backbone.js, javascript, jquery

Solution

The trick is that backbone has an optional dependency on other libs for some specific features.

The `$` variable of backbone is set to this at start time :

Backbone.$ = root.jQuery || root.Zepto || root.ender || root.$;

so in this case, backbone was trying to forward some processing to jQuery (or one of the other).

Of course, this dependency implies that jQuery/X must be available before backbone is loaded...

Ordering jQuery and backbone loading solves the problem.

Problem

In my single page app using backbone.js, I get this error : `TypeError: Backbone.$ is undefined` while trying to access the sync API. The sync API was working previously. I can't find what I broke...

Original source