If register as an AMD module, do not create a global, since the goal is to not leak out globals in that case.

This commit is contained in:
jrburke
2011-10-19 10:07:39 -07:00
parent e68d95dcaa
commit 6241343b33

View File

@@ -56,22 +56,17 @@
exports = module.exports = _; exports = module.exports = _;
} }
exports._ = _; exports._ = _;
} else { } else if (typeof define === 'function' && define.amd) {
// Exported as a string, for Closure Compiler "advanced" mode.
root['_'] = _;
// Register as a module with AMD. Use a named module since underscore // Register as a module with AMD. Use a named module since underscore
// can be used in optimization schemes that do not understand anonymous // can be used in optimization schemes that do not understand anonymous
// modules, and the if it is used on a page with an AMD loader, a load // modules, and the if it is used on a page with an AMD loader, a load
// error could occur. This work is done in addition to exporting a global // error could occur.
// on root since the web page could use an AMD loader to load the module define('underscore', function() {
// but still want to use the global reference. Test pages are a good return _;
// example. });
if (typeof define === 'function' && define.amd) { } else {
define('underscore', function() { // Exported as a string, for Closure Compiler "advanced" mode.
return _; root['_'] = _;
});
}
} }
// Current version. // Current version.