If shim not used in your example, then the Backbone object that you pass as a parameter will be undefined, since Backbone is not AMD compatible and does not return an object for using RequireJS.
define(['backbone'], function (Backbone) {
To give a little context, I will use code that optimizes the r.js optimizer, but I will simplify it for this example. It helped me understand the essence of this by reading what the optimizer produces.
An agreed trunk would be something like this:
// Create self invoked function with the global 'this' // passed in. Here it would be window define("backbone", (function (global) { // When user requires the 'backbone' module // as a dependency, simply return them window.Backbone // so that properites can be accessed return function () { return global.Backbone; }; }(this)));
The point is to provide RequireJS with something to return to you when you ask for the module, and it will guarantee that it will be loaded first before doing this. In the case of the optimizer, he simply inserts the library into his hands.
Simon Smith Dec 31 '13 at 3:04 on 2012-12-31 03:04
source share