gpt4 book ai didi

javascript - 如何传递 jslint 并将全局变量传递给我的 IIFE?

转载 作者:行者123 更新时间:2023-12-03 06:02:42 25 4
gpt4 key购买 nike

jslint 不喜欢这个

}(this));

但这就是我将全局变量传递给在客户端和服务器上运行的 IIFE 的方式。

如何更改它?

我想在不设置任何选项的情况下传递 jslint。

最佳答案

它需要跳过相当多的环节,但您可以定义这个函数,它传递 JSLint 并返回对全局对象的引用:

function getGlobal() {
// just creating a function here so that we can get at the Function constructor
// via noop.constructor
var noop = function () {
// dummy statements so the linter doesn't complain about an
// empty block or unused variables
var a = null;
return a;
};

return noop.constructor("return this")();
}

请注意,此函数本身不需要在全局范围内定义。您可以定义它并在 IIFE 中调用它。

关于javascript - 如何传递 jslint 并将全局变量传递给我的 IIFE?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39689893/

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