How does jQuery protect overwriting jQuery and $

后端 未结 5 1393
猫巷女王i
猫巷女王i 2020-12-29 16:56

These variables are located immediately after defining a local copy of jQuery in the jQuery source.

// Map over jQuery in case of overwrite
_jQuery = window         


        
5条回答
  •  臣服心动
    2020-12-29 17:28

    If you were to include another library like prototype, which uses $, then jQuery needs to have a reference of both $ and window.jQuery in order to support the jQuery.noConflict() function, etc...

    http://api.jquery.com/jQuery.noConflict/

    $ is used because it is convenient, but this comes at the price that it may be used by more than one library.

    Does that help?

提交回复
热议问题