diff --git a/README.md b/README.md index 3fab333ef..5333ab7d3 100644 --- a/README.md +++ b/README.md @@ -61,15 +61,14 @@ load('lodash.js'); In an AMD loader like [RequireJS](http://requirejs.org/): ~~~ js -// opt-in -define.amd.lodash = true; - +// Lo-Dash is defined as an anonymous module so, through path mapping, it can be +// referenced as the "underscore" module require({ 'paths': { - 'lodash': 'path/to/lodash' + 'underscore': 'path/to/lodash' } }, -['lodash'], function(_) { +['underscore'], function(_) { console.log(_.VERSION); }); ~~~ diff --git a/lodash.js b/lodash.js index e4d5038d5..771068301 100644 --- a/lodash.js +++ b/lodash.js @@ -2796,23 +2796,20 @@ else { freeExports._ = lodash; } - } else { - // in a browser or Rhino + } + // in a browser or Rhino + else { + // Expose Lo-Dash to the global object even when an AMD loader is present in + // case Lo-Dash was injected by a third-party script and not intended to be + // loaded as a module. The global assignment can be reverted in the Lo-Dash + // module via its `noConflict()` method. 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() { + // some AMD build optimizers, like r.js, check for specific condition patterns like the following: + if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) { + // define as an anonymous module so, through path mapping, it can be + // referenced as the "underscore" module + define(function() { return lodash; }); } diff --git a/lodash.min.js b/lodash.min.js index 935626073..fa4a6b962 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -23,4 +23,4 @@ return b==D||b==G?a.length:T(a).length},some:w,sortBy:function(a,b,c){if(q(b))c& S(b)+"))==null?'':_['escape'](__t))+'"}).replace(c.interpolate||$,function(a,b){return"'+((__t=("+S(b)+"))==null?'':__t)+'"}).replace(c.evaluate||$,function(a,b){return"';"+S(b)+";__p+='"})+"';";c.variable||(a="with(object||{}){"+a+"}");var a='var __t,__j=Array.prototype.join,__p="";function print(){__p+=__j.call(arguments,"")}'+a+"return __p",f=Function(c.variable||"object","_",a);if(b)return f(b,i);d.source="function("+(c.variable||"object")+"){"+a+"}";return d},throttle:function(a,b){var c,d,f, e,g,i,k=ja(function(){d=g=o},b);return function(){c=arguments;e=this;i||(i=J(function(){i=h;d&&a.apply(e,c);k()},b));g?d=n:f=a.apply(e,c);k();g=n;return f}},times:function(a,b,c){c&&(b=u(b,c));for(c=0;c
    - +