Breaking my javascript into modules, am I doing this right?
<p>I'm using the javascript module pattern, and have this so far:</p>

<pre><code>var APP;
if(APP == undefined) {
  APP = {};
}

APP = (function() {
    var userId = -1;
    var privateVar = '';

    var _init = function($userId) {
       userId = $userId;
    };
    var _publicMethod = function($id){
        privateVar = id;
    };
    return {
        init = function($userId) {
             _init($userId);
         },
        publicMethod = function($id) {
           _publicMethod($id);
        }
    };
})();
</code></pre>

<p>I then have a common utils module:</p>

<pre><code>APP.utils = (function(){

})();
</code></pre>

<p>And then per page I am planning on having a module, so I don't wireup events (button clicks etc) for no reason on pages where these DOM elements don't event exist:</p>

<pre><code>APP.homePage = (function(){
     return {

     };
})();
</code></pre>

<p>So each module will have a init() method that I will call on the page to run things that have to be run (e.g. wiring up events, setting variables like say userId etc):</p>

<pre><code>$(document).ready(function() {
   APP.init(&lt;%= user.id %&gt;);
   APP.homePage.init('abc');
});
</code></pre>

<p>So now if the files get too big, I can break them out into separate files also.</p>

<ol>
<li><p>What if one module needs to call another, I guess the only way for this to work is to do this via the public api right?
e.g. what if homePage needs userId, should I pass that in the homePage#init method?</p></li>
<li><p>How is my coding style, any obvious style that is not considered best practise?</p></li>
<li>Any comments on this approach?  Is it good in general?</li>
</ol>
