Permalink
Browse files

Optionally registers as AMD module

  • Loading branch information...
1 parent 1aa309b commit d12b5beb6156bde79d1532b429c925bae8025ff8 @jrburke jrburke committed Nov 6, 2013
Showing with 12 additions and 0 deletions.
  1. +12 −0 underscore.js
View
@@ -1284,4 +1284,16 @@
});
+ // AMD registration happens at the end for compatibility with AMD loaders
+ // that may not enforce next-turn semantics on modules. Even though general
+ // practice for AMD registration is to be anonymous, underscore registers
+ // as a named module because, like jQuery, it is a base library that is
+ // popular enough to be bundled in a third party lib, but not be part of
+ // an AMD load request. Those cases could generate an error when an
+ // anonymous define() is called outside of a loader request.
+ if (typeof define === 'function' && define.amd) {
+ define('underscore', [], function() {
+ return _;
+ });
+ }
}).call(this);

0 comments on commit d12b5be

Please sign in to comment.