api.jquery.com
api.jquery.com copied to clipboard
Document window requirement for CommonJS environment
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 );
Where do you suggest we document this?
I'm not sure. We'll discuss in the next meeting though.
I forgot about this for a while. I've added it to the agenda for the next meeting.
@kswedberg Per the meeting, what do you think about adding another page? Perhaps there are other issues that don't really fit?
Also, the issue has been updated. jQuery will be included in CommonJS by passing in a window.
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...
@timmywil A long time is passed since this issue was opened. What's the current status of jQuery in that regard?