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
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.