In almost every Backbone/Require.js project you will see models and views that look similar to this:
define([
'jquery',
'underscore',
'backbone'
], function ($, _, Backbone) {
//Some code goes here, perhaps a Backbone model or view
});
But, assuming that you set up your Require.js shims correctly (with the Backbone shim including something like deps: ["underscore", "jquery"]
) you only need to define Backbone--defining Backbone as a dependency implicitly defines jQuery and Underscore as dependencies as well! Thus this would also be correct:
define([
'backbone'
], function (Backbone) {
//Some code goes here, perhaps a Backbone model or view
});
Personally, I would define jQuery or Underscore in a file that explicitly used their functions--but in something like a simple no-frills Backbone model file, they seem like cruft.
Why do I so frequently see the pattern of superfluous jQuery and Underscore definitions? Why has this become an unquestioned best practice?