Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does window.jQuery and window.$ mean?

Are they native properties of window if so why is it called jQuery, surely jquery came after javascript

Edit: I was looking through jquery.js and found these two lines which made me wonder about what they mean exactly. If wouldn't window.Jquery be null since JQuery is not a variable of window?

_jQuery = window.jQuery,

_$ = window.$,
like image 739
code511788465541441 Avatar asked Jun 04 '13 16:06

code511788465541441


People also ask

What does window mean in JavaScript?

A global variable, window , representing the window in which the script is running, is exposed to JavaScript code. The Window interface is home to a variety of functions, namespaces, objects, and constructors which are not necessarily directly associated with the concept of a user interface window.

What is difference between document and window in JavaScript?

window is the execution context and global object for that context's JavaScript. document contains the DOM, initialized by parsing HTML. screen describes the physical display's full screen.


1 Answers

I will pull from an article I linked to in a comment above:

As discussed in the JavaScript Basics section, valid names in JavaScript can be pretty much anything, as long as they don't begin with a number and don't include a hyphen. So, the $ in the code above is just a shorter, more convenient name for the jQuery function; indeed, in the jQuery source code, you'll find this near the end:

// Expose jQuery to the global object
window.jQuery = window.$ = jQuery;

When you call the $() function and pass a selector to it, you create a new jQuery object. Of course, in JavaScript, functions are objects too, so that means that $ (and jQuery, of course) has properties and methods, too. For example, you can refer to the $.support property for information on what the current browser environment supports, and you use the $.ajax method to make an AJAX request.

Basically, jQuery (when you include it) creates functions at window.$ and window.jquery. Then it sets $ equal to both of those to $ for convenience.

like image 187
David Ziemann Avatar answered Oct 18 '22 19:10

David Ziemann