我定义并执行了一个函数..
var exitPopup = (function($) {
var someVar = false;
var someFunc = function() { doSomething(); };
})(jQuery);
我的问题是,是否可以访问其中的变量和函数?如何在不修改上述代码(它是一个插件)的情况下调用 someFunc
?
我会这样想
exitPopup.someFunc();
但是,是的,不..
最佳答案
根据 the MDN docs of IIFE ,
IIFE is a design pattern which is also known as Self-Executing Anonymous Function and contains two major parts. The first is the anonymous function with lexical scope enclosed within the Grouping Operator (). This prevents accessing variables within the IIFE idiom as well as polluting the global scope.
所以,不,它无法访问。
关于javascript - 访问 IIFE 函数变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50070794/