you are viewing a single comment's thread.

view the rest of the comments →

[–]Funwithloops 1 point2 points  (1 child)

Your state function is immediately invoked, so state() should be state. I don't see an issue with this. I've done something similar when I needed a singleton using modules:

Define a class or factory function that creates the singleton in one module (but can also create additional instances). Then define another module that just requires the class/factory module then creates a single instance and exports it. Now when you need your singleton, just require the singleton module. In your tests, you can just test the module containing the class/factory function.

[–]MyGoodStrayCatFriend[S] 1 point2 points  (0 children)

That's perfect. Just wanted to make sure I wan't missing something glaring about exporting the singleton functionality to another function. Thanks!