I\'m writing client-side code and would like to write multiple, modular JS files that can interact while preventing global namespace pollution.
index.html
I think what you want is https://github.com/component/component.
It's synchronous CommonJS just like Node.js, it has much less overhead, and it's written by visionmedia who wrote connect and express.
You can do it like this:
-- main.js --
var my_ns = {};
-- util.js --
my_ns.util = {
map: function () {}
// .. etc
}
-- index.js --
my_ns.index = {
// ..
}
This way you occupy only one variable.