Extend current objects with jQuery

// Navigation component scripts
var bobcat = bobcat || {};

bobcat.components = $.extend(bobcat.components, {

    "navigation": (function() {
        this._init = function() {
            // some initial functions
        }

        return {
            init: this._init
        }
    })()
});


Encapsulation In JavaScript.

Example :


var mainmodule = {};

mainmodule.newModule = (function() {
    var that = this;
    this._setup = function() {
        // do some setup
    };

    this._init = function() {
        that._setup(); // and do more here
    };
    return {
        init: this._init
    }
})();


Note:

use that pattern

private vars with "_" prefix