How to access variable dynamically inside an anonymous function/closure?

后端 未结 3 1737
甜味超标
甜味超标 2021-01-14 00:22

To keep the global namespace clean, my JavaScript code is wrapped like this:

(function() {
    /* my code */
})();

Now I have some variable

3条回答
  •  梦谈多话
    2021-01-14 00:26

    (function(globals) {
        /* do something */
        globals[varname] = yourvar;
    })(yourglobals);
    

提交回复
热议问题