So you'd need to setup an empty file in your project called backbone.js
and then put the Backbone.sync
code in it. The only difference is that at the top you'd need to require the original Backbone file (e.g. ../vendor/backbone/backbone.min.js
) with a Backbone
argument name. Then put return Backbone;
at the end. Anywhere else in your project where you need Backbone require your new backbone.js
file (or, even better, set that up to be backbone
in your RequireJS config).
The auth.js
module is just a short file that I wrote - it's quite specific to the project.
The example above is assuming that you're using the non-AMD version of Backbone, so Backbone.sync
is in the global scope. When you assign the new function to Backbone.sync
it will therefore over-write the original - just like reassigning any variable.
If you were using the AMD version of Backbone it would be a little trickier. You'd need to setup a file where you import in the AMD Backbone object, then override the Backbone.sync
method, and then return the new version. From then on you'd use that newly created file as your Backbone definition (so you'd only require the original Backbone file once at the top of that file).
It's good to know that the AMD versions are kept up to date - that has always been my concern with using them.
Do Backbone plugins generally work well with the AMD versions?
This is using the non-AMD version of Backbone and LoDash. I prefer to use the official non-AMD version of Backbone.
I completely misread the operator precedence table. Good point!