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.$,
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With