3. Step 3 - Initialize the Application

We initialize the application by defining its namespace and MVC sub-namespaces. Namespaces are an important concept in software engineering and many programming languages, including Java and PHP, provide specific support for namespaces, which help grouping related pieces of code and avoiding name conflicts. Since there is no specific support for namespaces in JavaScript, we use special objects for this purpose (we may call them "namespace objects"). First we define a root namespace (object) for our app, and then we define three sub-namespaces, one for each of the three parts of the application code: model, view and controller. In the case of our example app, we may use the following code for this:

var pl = { m:{}, v:{}, c:{} };

Here, the main namespace is defined to be pl, standing for "Public Library", with the three sub-namespaces m, v and c being initially empty objects. We put this code in a separate file initialize.js in the c folder, because such a namespace definition belongs to the controller part of the application code.