Bhavik Patel Bhavik Patel -4 years ago 71
Javascript Question

How JQuery assign function name to $?

I want to know
How JQuery assign function name to $ ?

Answer Source

This is done at line 9384 of the uncompressed library (see http://code.jquery.com/jquery-1.7.2.js)

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

where jQuery on the right side of this assignment is the function-scoped reference (starting at line 22): of course you could create your favourite shortcut (e.g. _) doing something like

window._ = window.jQuery

after you've loaded the library, so you can use _ instead of $ or jQuery.

If you asked this because you have loaded some other libraries and you have a conflict with the $ reference, just take a look at jQuery.noConflict() method

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download