gpt4 book ai didi

javascript - 为什么jquery在覆盖的情况下需要_$?

转载 作者:行者123 更新时间:2023-11-29 10:25:32 25 4
gpt4 key购买 nike

var 
// Will speed up references to window, and allows munging its name.
window = this,
// Will speed up references to undefined, and allows munging its name.
undefined,
// Map over jQuery in case of overwrite
_jQuery = window.jQuery,
// Map over the $ in case of overwrite
_$ = window.$,

jQuery = window.jQuery = window.$ = function( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init( selector, context );
};

为什么 jQuery 需要“_$ = window.$”或“_jQuery = window.jQuery”?这对我来说没有意义,但如果没有这两行,框架就无法工作。

感谢任何帮助..

最佳答案

它会在覆盖 $ 和 jQuery 的值之前保存对它们的引用,以便您可以调用 jQuery.noConflict() 并恢复这些值。

关于javascript - 为什么jquery在覆盖的情况下需要_$?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2380451/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com