Sungam Yang
Sungam Yang

Reputation: 615

About Revealing module pattern in JavaScript

I'm currently building a mobile web application with jQM, Highcharts and HTML5.

To maintain the JavaScript code, I decided to apply Revealing module pattern to the code.

Here is my code.

var MobileWebV1 = function () {

    function _buildPanelMenu(pageId, isNormalMenu) {
    }

    function _buildHeaderBar(pageId, isNormalMenu) {
    }

    return {
        buildPanelMenu: _buildPanelMenu,
        buildHeaderBar: _buildHeaderBar
    };
}();

I'm wondering if I can add another hierarchy to categorize methods in the object.

I want to add 'UserInterface' and 'Util.' In that case, I can call the method like this: MobileWebV1.UserInterface.buildPanelMenu('pageHome', false);

I tried to modify my objecy, but I'm still stuck with the current issue.

If you know the answer, then please share your knowledge.

Upvotes: 0

Views: 83

Answers (1)

Bergi
Bergi

Reputation: 664434

Just nest the object literals:

return {
    Util: {
        …
    },
    UserInterface: {
        buildPanelMenu: _buildPanelMenu,
        buildHeaderBar: _buildHeaderBar
    }
};

Upvotes: 1

Related Questions