In the source code ( caution : 10,000 lines) we have the following:

var // Map over jQuery in case of overwrite _jQuery = window.jQuery, // Map over the $ in case of overwrite _$ = window.$; jQuery.noConflict = function( deep ) { if ( window.$ === jQuery ) { window.$ = _$; } if ( deep && window.jQuery === jQuery ) { window.jQuery = _jQuery; } return jQuery; }; 

It is not clear why we enter _$ and _jQuery ...

While preparing the question I understood how it works; I present the answer below.

    1 answer 1

    Imagine that besides jQuery , we also have the XXX library, which also uses the window.$ Variable as the main identifier.

    1. We load the XXX library - the variable window.$ Is defined.

    2. We want to use it (the window.$ Variable) to access the XXX library; but at the same time, after loading the XXX library, we load jQuery , which will override window.$ for itself; BUT, first (before redefining) jQuery will back up the value of the variable window.$ Into its local variable _$ :

       var // Map over jQuery in case of overwrite _jQuery = window.jQuery, // На это пока не обращаем внимание. // Map over the $ in case of overwrite _$ = window.$; // Вот здесь. 

    That is, after loading jQuery in the variable window.$ will be jQuery , and the XXX library will live in the local variable _$ the jQuery function .

    That is why the documentation states that the jQuery.noConflict() method (if we want to eliminate conflicts) must be called immediately after loading the library and before using it:

    In case of jQuery in your page.

    That is, when we call the jQuery.noConflict() method, the following will occur:

     jQuery.noConflict = function( deep ) { // Здесь будет `true`, так как у нас в `window.$` на данный момент // находится `jQuery`. if ( window.$ === jQuery ) { // Так как мы хотим исключить конфликты, то мы устанавливаем // в качестве значения переменной `window.$` сделанный ранее бэкап, // то есть возвращем исходное значение этой переменной до // загрузки `jQuery`. window.$ = _$; // Теперь в `window.$` опять живёт библиотека `XXX`. } if ( deep && window.jQuery === jQuery ) { window.jQuery = _jQuery; } return jQuery; }; 

    With _jQuery by analogy ...


    Editing and cuffing are accepted, since I just started learning jQuery and I can be wrong.

    • one
      Although I know how it works, I read it with pleasure, so that I could make out all the functions! - user207618