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

后端 未结 3 1704
甜味超标
甜味超标 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:23

    evil solution/hack: Put the variable you need in a helper object obj and avoid having to change current uses to dot notation by using use with(obj){ your current code... }

提交回复
热议问题