Modules not Globals
Often newer JS developers ask when they should turn something into a standalone module. When should that function turn into its own file? There are lots of things we could talk about with componentized architecture. But there is a single thing that should be a massive flashing sign that you need a module.
That thing is global variables. Anytime you touch window. or global. or some other shared variable scope.
Next time you are trying to share things through a global scope... grab a module that you can require into many modules. Usually these wrappers are incredibly light, and they will make your code much cleaner.
If you enjoyed this article please share it! New articles, stories and poems also go out by email. Thanks! -Daniel