I\'ve been writing web applications for a while now , and everyone knows the one
ID: 648496 • Letter: I
Question
I've been writing web applications for a while now , and everyone knows the one golden rule not to assign variables to the window object , don't ever assign a variable without using var.
My question is, why not? In my opinion it is a lot easier especially nice in SPA's to attach objects to the global scope when you have many different scopes in different modules for different modal views if you want to share data.
Now, lets just assume for the sake of this question that I will never ever have the problem of accidentally overriding global variables, meaning - I will take the responsibility to make sure I have very good names and they will never overlap. If you take that into consideration , then I can't see any other reason why global variables are just bad practice.
Explanation / Answer
For a few reasons:
It often forces you to choose longer names, where a shorter one would be more clear and concise within a limited scope. For example, filter versus MyModuleNameFilter.
The process of "taking the responsibility to make sure you have very good names and they will never overlap" gets increasingly difficult the larger your code base gets (and the older you get for that matter).
You are unable to share code with anyone else who subscribes to the same philosophy.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.