特别是我想定义
应该存储jQuery的本地jQuery(var jQuery)(以及本地$).
问题是jQuery直接使用window对象操作:
// Expose jQuery to the global object
window.jQuery = window.$ = jQuery;
})(window);
Run Code Online (Sandbox Code Playgroud)
这是来自jQuery 1.6.4的引用
我该如何解决这个问题?
PS:我的特殊问题是为第三方网站使用写一些片段
,如果我包含jQuery,可能会出现与第三方js代码的一些不兼容性.目前我正在做以下事情:
// here some license notes about jQuery included
(function() {
if (typeof jQuery === "undefined") {
// jQuery code as it is goes here
}
// my code
})();
Run Code Online (Sandbox Code Playgroud)
您可以传递true给$ .noconflict()以使jQuery从全局范围中删除其所有变量:
(function($) {
var jQuery = $.noconflict(true);
// From there on, window.jQuery and window.$ are undefined.
var $ = jQuery;
// Do something with the local jQuery and $...
})(jQuery);
Run Code Online (Sandbox Code Playgroud)