How to mangage javascript files and encapsulate JavaScript/jQuery functions
<p>I need to write &amp; manage a lot of JavaScript code for current project.</p>

<p>I separate them into multiple .js files mainly based on module.</p>

<p>So, now i have for example:</p>

<pre><code>Map.js // deal with google map issue
Common.js // common functions that will share by all modules
User.js // user module js code
Geofence.js // geofence module js code
etc.....
</code></pre>

<p>For example, inside my User.js file</p>

<p>what if i want to declare a function that only used inside the User.js file, not accessible by outside. what can i do?</p>

<pre><code>var User = {};

User.registerModule = function () {
    $('#user').click(function () {
        Common.showLeftScrollbar();

        getAllUsers();

        // ...
    });
}

function getAllUsers(){ // how to hide this function
    // get
    return users;
}
</code></pre>

<p>So, in my home page, i only need to coordinate with multiple .js files. Access what allows to access.</p>

<pre><code>  $(document).ready(function (data) {

        GoogleMap.initialiseGoogleMap();

        Common.refreshRightScrollbar();

        User.registerModule();

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

<p>It is my first time to write js and not enough time to study a whole book. So, please, in your opinion, is this structure ok with many js code? and how to hide functions that i dont want outside to access? </p>
