uhateoas
8/19/2013 - 1:55 PM

Module Pattern The module pattern gives us the ability to create private and public methods. For example, in the code below, the variable _

Module Pattern

The module pattern gives us the ability to create private and public methods. For example, in the code below, the variable _index and the method privateMethod are private. increment and getIndex are public.

var Module = (function() {
    var _index = 0;
    var privateMethod = function() {
        return _index * 10;
    }
    return {
        increment: function() {
            _index += 1;
        },
        getIndex: function() {
            return _index;
        }
    };     
})();