javascript – 在ES5严格模式函数中加载jQuery

我想在IIFE范围内导入jQuery,如下所示:

(function (window, document) {
    "use strict";
    /* Content of jquery.min.js goes here */
    /* Code that uses $goes here */
}(window, document));

现在,一旦这段代码运行,我就会遇到严格的模式违规,可能是因为jQuery本身不符合:

In strict mode code, functions may be declared only at top level or
immediately within another function.

有没有办法在单个函数范围内加载jQuery,同时仍然保留依赖它的其余代码的严格模式?

最佳答案 这里回答:
https://github.com/jquery/jquery/issues/1779

jQuery isn’t meant to be run with “use strict” in effect. See the comment at the top of the unminified file for the reason, or look at 07001 for more information. You are not gaining anything by attempting to force jQuery into strict mode against its will, doing so prevents interoperability with any third-party libraries that are not use-strict compatible.

点赞