4 ms·
Globals make it really difficult to test, reuse, or repurpose code. And you can only ever have one instance of a given global, so if you want multiple instances
by cimmanom 8y ago
Globals make it really difficult to test, reuse, or repurpose code. And you can only ever have one instance of a given global, so if you want multiple instances of your widget you face really ugly refactoring.
If you google for it there should be plenty of good resources on this topic. It sounds like maybe you’re relatively new to programming - it only takes running into this situation once to start to understand the reasons for avoiding them.
They’re especially dangerous in JavaScript because of the way it handles scoping. If you accidentally miss a “var” or “let” inside a function you could find yourself mutating global instead of local data.
Vuex lets you scope your data to a module. It also as I described above lets you limit mutations to a known set of operations, which becomes important in a large or long-lived codebase.
- LiterallyDoge 8y agoThanks good points I'll keep at the research.