From 38c0b375ec36973c8bbab9eb0888b69673540670 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 22 Apr 2012 18:27:52 -0400 Subject: [PATCH] lodash: Add comment about opt-in AMD support. [jddalton] Former-commit-id: f2819c9b2e19b5f999139b89555fa931dfe3b909 --- lodash.js | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/lodash.js b/lodash.js index 878bf964c..2ca585dcf 100644 --- a/lodash.js +++ b/lodash.js @@ -2747,7 +2747,7 @@ /*--------------------------------------------------------------------------*/ - // expose lodash + // expose Lo-Dash if (freeExports) { // in Node.js or RingoJS v0.8.0+ if (typeof module == 'object' && module && module.exports == freeExports) { @@ -2757,15 +2757,25 @@ else { freeExports._ = lodash; } - } - // via an AMD loader - else if (typeof define == 'function' && typeof define.amd == 'object' && define.amd && define.amd.lodash) { - define('lodash', function() { - return lodash; - }); - } - // in a browser or Rhino - else { + } else { + // in a browser or Rhino window._ = lodash; + + // Expose Lo-Dash as an AMD module, but only for AMD loaders that understand + // the issues with loading multiple versions of Lo-Dash in a page that all + // might call `define()`. The loader will indicate they have special + // allowances for multiple Lo-Dash versions by specifying + // `define.amd.lodash=true`. Register as a named module, since Lo-Dash can + // be concatenated with other files that may use `define()`, but not use a + // proper concatenation script that understands anonymous AMD modules. + // Lowercase `lodash` is used because AMD module names are derived from + // file names, and Lo-Dash is normally delivered in a lowercase file name. + // Do this after assigning Lo-Dash the global so that if an AMD module wants + // to call `noConflict()` to hide this version of Lo-Dash, it will work. + if (typeof define == 'function' && typeof define.amd == 'object' && define.amd && define.amd.lodash) { + define('lodash', function() { + return lodash; + }); + } } }(this));