This is how I usually do it:
var TopLevel = TopLevel || {}; //Exentd or Create top level namespace TopLevel.FirstChild = TopLevel.FirstChild || {}; //Extend or Create a nested name inside TopLevel
Using this method allows for security between files. If TopLevel already exists, you assign it to the TopLevel variable; if not, you will create an empty object that can be extended.
Assuming that you want to create an application that exists in the application namespace and is expanded in several files, you need files that look like this:
File 1 (library):
var Application = Application || {}; Application.CoreFunctionality = Application.CoreFunctionality || {}; Application.CoreFunctionality.Function1 = function(){
File 2 (library):
var Application = Application || {}; Application.OtherFunctionality = Application.OtherFunctionality || {}; Application.OtherFunctionality.Function1 = function(){
File 3 (working):
//call the functions (note you could also check for their existence first here) Application.CoreFunctionality.Function1(); Application.OtherFunctionality.Function1();
Josh hatland
source share