aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimmy Willison <timmywillisn@gmail.com>2013-11-15 17:18:22 -0500
committerTimmy Willison <timmywillisn@gmail.com>2013-11-15 17:18:22 -0500
commit8f7db68cbf1cdc3677d89dc1191bc50c8d47a82f (patch)
treed2588fa726680959c56dd73a9d2ce69b63be3a53
parent6fde9752599f035da5e328b54a1e23e075e4ad45 (diff)
downloadjquery-8f7db68cbf1cdc3677d89dc1191bc50c8d47a82f.tar.gz
jquery-8f7db68cbf1cdc3677d89dc1191bc50c8d47a82f.zip
Fixes #14549. Execute the factory immediately when CommonJS is used in the browser.
-rw-r--r--src/intro.js24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/intro.js b/src/intro.js
index 01803d9af..4b2f45171 100644
--- a/src/intro.js
+++ b/src/intro.js
@@ -15,17 +15,21 @@
(function( window, factory ) {
if ( typeof module === "object" && typeof module.exports === "object" ) {
- // Expose a jQuery-making factory as module.exports in loaders that implement the Node
- // module pattern (including browserify).
- // This accentuates the need for a real window in the environment
+ // For CommonJS and CommonJS-like environments where a proper window is present,
+ // execute the factory and get jQuery
+ // For environments that do not inherently posses a window with a document
+ // (such as Node.js), expose a jQuery-making factory as module.exports
+ // This accentuates the need for the creation of a real window
// e.g. var jQuery = require("jquery")(window);
- module.exports = function( w ) {
- w = w || window;
- if ( !w.document ) {
- throw new Error("jQuery requires a window with a document");
- }
- return factory( w );
- };
+ // See ticket #14549 for more info
+ module.exports = window.document ?
+ factory( window ) :
+ function( w ) {
+ if ( !w.document ) {
+ throw new Error("jQuery requires a window with a document");
+ }
+ return factory( w );
+ };
} else {
factory( window );
}