PaulUithol/Backbone-relational — Issue #57: Support Asynchronous Module Loading (require.js)
Author: aiwilliams
Created: 2011-12-21 20:36:39+00:00
State: open

This is becoming more and more an accepted practice. jQuery 1.7 and even jQuery Mobile (in a branch) are supporting Asynchronous Module Loading. I have modified a copy of backbone-relational.js to employ a method which @jrburke implements here: https://github.com/jrburke/backbone/tree/optamd3. For this project:

```javascript
(function(root, factory) {
// Set up appropriately for the environment.
if (typeof exports !== 'undefined') {
// Node/CommonJS
factory(root, exports, require('underscore'), require('backbone'));
} else if (typeof define === 'function' && define.amd) {
// AMD
define('backbone-relational', ['underscore', 'backbone', 'exports'], function(_, Backbone, exports) {
factory(root, exports, _, Backbone);
});
} else {
// Browser globals
factory(root, {}, root._, root.Backbone);
}
}(this, function(root, exports, _, Backbone) {
// Backbone.Relational extensions to Backbone
// NOTE: the few lines assigning the exports, _, and Backbone are no longer needed
}));
```

I have not tested this in Node, nor without Require.js.