Modules not Globals

Published: 11 Jun 2015

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.