Dynamic call of module pattern function I started reading about JavaScript patterns, and I really liked module pattern.
So I created some module:

var App = (function (parent, $) {
    function myPrivateFunc () {
        // Some private stuff
    }

    return {
        myPubFunc: myPrivateFunc,
        publicFunction: function () {
            // Do some stuff
        }
    };
})(App || {}, jQuery);


Now I want to call some functions on page but only functions I need on that specific page. I got idea to add data-modules attribute to body, and then load modules I demanded on that attribute. I did that this way:

var modules = $('body').data('modules').split(" ");

for (var i = modules.length - 1; i &gt;= 0; i--) {
    App[modules[i]]();
}


My question is: Is this a good way to achieve what I wanted? I tested, it's working fine, but I'm a little suspicious about this dynamic calling. Is there better solutions (preferably not libraries) out there? If this is not good, why it isn't?
Instead of adding data-properties to the body tag, and waiting for / relying on jQuery, just use an inline script:

&lt;script type="text/javascript"&gt;
    var modules = /* echo the needed modules here */;
    for (var i=0; i&lt;modules.length; i++)
        App[modules[i]]();
&lt;/script&gt;