Global variables for node.js standard modules?

前端 未结 6 1445
故里飘歌
故里飘歌 2020-11-27 12:51

I know that global variables are bad.

But if I am using node\'s module \"util\" in 40 files in my framework, isn\'t it better to just declare it as a global variable

6条回答
  •  借酒劲吻你
    2020-11-27 13:03

    I have successfully been using the process object for passing around my configuration object. While in theory suffering from the exact same issues as mentioned above (encapsulation, testability and so forth) it works fine when using only non-state modifying properties (a hash table with primitives, basically).

提交回复
热议问题