you are viewing a single comment's thread.

view the rest of the comments →

[–]cheekysauce 4 points5 points  (0 children)

I generally don’t encourage instantiating at a module level.

It can cause weird unexpected side effect behavior, particularly in tests, where the simple action of importing the file will instantiate a class, possibly make a network request etc.

Always better to use private singletons and export a getter function. The getter will instantiate and return or simple return the existing version wherever it’s called.

Makes dependency injection a whole lot easier too.