Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm fairly new to JS coding outside of little functions that use jQuery, but I am fairly aware of patterns and practices. I would appreciate some input on my approach so far. Inside my main (revealing) module, I would like to have objects that expose all their methods for use inside the main module, like my commands object, but then I would like to expose a limited set of commands for clients of the main module. I am currently looking at this:

JavaScript
var rotatingBannerController = (function() {
    "use strict";

    var imageList = (function() {
        var buffer = new CBuffer();
        return {
            rotate: function() { buffer.rotateLeft(); }
        }
    })();

    var privateInit = function() {
        // Do init stuff like load list and config.
    };

    var commands = (function() {
        return {
            rotate: function() { imageList.rotate(); },
            init: privateInit
        }
    })();

    return {
        config: config,
        commands: { init: commands.init }
    }

})();


The reason for the commands object is to encapsulate my commands neatly for use within the module.

I am deliberately avoiding more advanced topics such as conctructors and prototypes here, until I establish a working module. I will then maybe upgrade the module to a fully fledged Object.
Posted
Updated 12-Dec-14 21:26pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900