Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UMD-ready Underscore #1303

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 36 additions & 24 deletions underscore.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,41 @@
// (c) 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
// Underscore may be freely distributed under the MIT license.

(function() {
// UMD module definition (https://github.com/umdjs/umd).
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(factory);
}
else if (typeof exports === 'object') {
// Export the Underscore object for **Node.js**, with
// backwards-compatibility for the old `require()` API.
if (typeof module === 'object' && module.exports) {
exports = module.exports = factory();
}
exports._ = factory();
} else {
// Save the previous value of the `_` variable.
var previousUnderscore = root._;

// Baseline setup
// --------------
// Instantiate the factory.
var underscore = factory();

// Establish the root object, `window` in the browser, or `exports` on the server.
var root = this;
// Browser globals. Add `_` as a global object via a string identifier, for
// Closure Compiler "advanced" mode.
root._ = underscore;

// Save the previous value of the `_` variable.
var previousUnderscore = root._;
// Run Underscore.js in *noConflict* mode, returning the `_` variable to its
// previous owner. Returns a reference to the Underscore object.
root._.noConflict = function() {
root._ = previousUnderscore;
return underscore;
};
}
}(this, function() {

// Baseline setup
// --------------

// Establish the object that gets returned to break out of a loop iteration.
var breaker = {};
Expand Down Expand Up @@ -51,19 +76,6 @@
this._wrapped = obj;
};

// Export the Underscore object for **Node.js**, with
// backwards-compatibility for the old `require()` API. If we're in
// the browser, add `_` as a global object via a string identifier,
// for Closure Compiler "advanced" mode.
if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
exports = module.exports = _;
}
exports._ = _;
} else {
root._ = _;
}

// Current version.
_.VERSION = '1.5.2';

Expand Down Expand Up @@ -1049,10 +1061,8 @@
// Utility Functions
// -----------------

// Run Underscore.js in *noConflict* mode, returning the `_` variable to its
// previous owner. Returns a reference to the Underscore object.
// *noConflict* stub. Returns a reference to the Underscore object.
_.noConflict = function() {
root._ = previousUnderscore;
return this;
};

Expand Down Expand Up @@ -1273,4 +1283,6 @@

});

}).call(this);
return _;

}));