I have a rails app with the following JavaScript file structure:
- assests/javascripts
- /application
- module1.js
.
.
.
- moduleN.js
- application.js
Each file looks like this:
var module1 = (function(){
//Lots of code
return {
//Public stuff
}
})();
Modules need access to each other and therefore expose some stuff.
application.js
//= require_tree ./application
I am wondering if there is a way to compile all of the code into an anonymous function; something like:
(function(){
//= require_tree ./application
})();
Which obviously doesn't work. What I'm currently doing is:
application.js
//= require ./begin.js
//= require_tree ./application
//= require ./end.js
begin.js is just (function(){ and end.js is })();.
Not the neatest solution.
This not only eliminates the global variables, but lets the compiler change their name to shorter ones for a lighter code and more unreadable. I am concerned with code confidentiality and don't want to expose module names, to make reverse engineering more difficult.
window. I think you need to expand on that, because I've never seen a case where a handful of global namespaces would be a problem.