I read with great interest schwern's thread about JavaScript's lack of includes and namespaces. A common answer for the include problem is that you can include your JavaScript "modules" via HTML like this:
but the problem, as Schwern pointed out, is that if module1.js wants to include module2.js, the user has to include both in HTML-space, which breaks encapsulation.
Sean Burke came up with a solution which addresses the problem by first loading a bootstrapping script, bootstrap.js.
I decided to try a different hack in HTML, by using hidden iframes. First, a disclamer: this was a quick hack, so it is certainly not perfect, and I wouldn't be surprised if someone invented it before, but I came up with this on my own. ;-) Let's see how it works. First, in test.html:
Then, in module1.html:module1.my_func()
module1.module2.my_func()
And in module2.html:
To summarize: