What does window.jQuery and window mean. $?

Are they window own properties, if so, why is it called jQuery, certainly jquery appeared after javascript

Change I was looking through jquery.js and found these two lines that made me think about what they mean. Had window.Jquery not been null since jQuery is not a window variable?

 _jQuery = window.jQuery, _$ = window.$, 
+7
source share
3 answers

I will write an article related to it in the comment above:

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

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

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

Basically, jQuery (when you turn it on) creates functions in a window. $ and window.jquery. Then, for convenience, he sets $ equal to both of them in $.

+8
source

jQuery is a javascript library

jQuery is a fast, small, and feature-rich JavaScript library. This makes things like crawling and manipulating HTML documents, handling events, animations, and Ajax much easier with an easy-to-use API that works across multiple browsers. By combining versatility and extensibility, jQuery has changed the way millions of people write JavaScript. http://jquery.com/

After enabling the script on the page, it will create jQuery and $ objects in the global context (window). This is not native.

it

 _jQuery = window.jQuery, _$ = window.$, 

They are internal mappings in case of overwriting. You can use the .noConflict function to restore the previous window.$ Value to prevent conflicts with prototype and other libraries

+4
source

window is the default global object /. Each time you assign a value and do not specify an explicit object to which it will be attached, then it will be assigned to the property of the global object, unless the local variable assigns it first (see section 3.b. of PutValue );

Any global property will be their property.

+2
source

All Articles