api.jquery.com icon indicating copy to clipboard operation
api.jquery.com copied to clipboard

Document window requirement for CommonJS environment

Open timmywil opened this issue 11 years ago • 7 comments

See http://bugs.jquery.com/ticket/13768.

jQuery needs a window object in order to be initialized correctly, but some environments do not have an available window object by default. For example, when requiring jQuery in a Node environment using jsdom:

// Define window
var window = jsdom.jsdom().createWindow();
// Require jQuery and pass in the created window
var $ = require("jquery")( window );

timmywil avatar May 08 '13 16:05 timmywil

Where do you suggest we document this?

kswedberg avatar May 08 '13 17:05 kswedberg

I'm not sure. We'll discuss in the next meeting though.

timmywil avatar May 08 '13 17:05 timmywil

I forgot about this for a while. I've added it to the agenda for the next meeting.

timmywil avatar Jun 27 '13 02:06 timmywil

@kswedberg Per the meeting, what do you think about adding another page? Perhaps there are other issues that don't really fit?

timmywil avatar Jul 04 '13 17:07 timmywil

Also, the issue has been updated. jQuery will be included in CommonJS by passing in a window.

timmywil avatar Jul 04 '13 17:07 timmywil

What about the use case of jQuery without a window? jQuery provides $.ajax which some very large frameworks require (like Backbone.js). If we could do

Backbone.$ = require('jquery')

And, at least get Backbone.$.ajax running we could unit test Backbone.js outside of the browser...

EvanCarroll avatar May 21 '15 02:05 EvanCarroll

@timmywil A long time is passed since this issue was opened. What's the current status of jQuery in that regard?

AurelioDeRosa avatar Oct 06 '15 20:10 AurelioDeRosa