At the moment every javasrcipt file in our project includes closure wrapper. Bef
ID: 650954 • Letter: A
Question
At the moment every javasrcipt file in our project includes closure wrapper. Before deploying all files are concatenated and minimized.
And i'm asking myself, do we really need all that closures OR one closure added after concatenation will do the job.
I can see only one reason not to do that - the variable we are sharing between files will get in the global namespace. But there is no conflict so is don't see any problem.
The real question is what other cons may be? Or more generally what approach is better - one closure or many?
Explanation / Answer
Yes, you need all the closures so the files are separate from each other.
If you concatenate more then one file inside the same function then they will share variables, just as if they had been global. The only advantage at this point would be insulating your code from external 3rd party Javascript.
In any case, I would say that the best thing you can probably do is use a Javascript modularization tool like RequireJS so you can stop worrying about concatenating and generating the files yourself.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.