Organizing Javascript

.Net programmer checking in.

At work I’ve been declared the go to Javascript guy. Which has me creating a ton of functionality for the web side of the business.

Now in .net I’m used to creating namespaces, business objects, Data objects, GUI elements, etc - all through Visual Studio.

Everything is kept nice and neat: namespaces become folders, objects are separate files within the folders, and in this way complexity can be managed. Of course .net takes care of putting everything together at compile time for me, all based on the objects I use for a particular project.

But how on earth do I handle this with Javascript?

Am I really going to have to put dozens of objects and functions in a single file?

Does Javascript support namespaces? Are there tools that will allow me to keep my code organized, and perhaps put it together as needed when I create includes/associations?

You don’t have to, but keep in mind that every extra file incurs extra HTTP overhead.

No, but you can fake it. It’s a good idea.

You can always use your favorite server-side templating or include system to assemble a Javascript file from multiple source files, if you want.