I've wanted to optimize project but faced with problem. I don't know how resolve this problem. I want to use immediate call functoins which initialize IS_LOCALHOST property and CONTEXT_PATH, but I can't get access to isLocalhost() function and constant properties (like port number). I try to put this as a parameter immediate call function but it references on document also I try to save refence like self: this and use this.self like peremeter and even util. I don't understand how I can resolve this problem. Please, help me to understand working solution.
var util = {
            WAR_FILE_NAME : 'app-name/',
            DEFAULT_TOMCAT_PORT : 8080,
            DEFAULT_SECURE_TOMCAT_PORT : 8443,
            /*** Pre construct block ***/
            IS_LOCALHOST : ( function () {
                var isLocalhost = false, hostWithPort = location.host;
                if ( hostWithPort.indexOf('localhost') !== -1 || hostWithPort.indexOf('127.0.0.1') !== -1 ) {
                    isLocalhost = true;
                }
                return isLocalhost;
            }() ),
            isLocalhost : function (){
                return this.IS_LOCALHOST;
            },
            CONTEXT_PATH : ( function (utilModule) {
                return location.hostname + ( location.port ? ':' + utilModule.DEFAULT_TOMCAT_PORT : '' ) + '/' + ( utilModule.isLocalhost() ? utilModule.WAR_FILE_NAME : '' );
            }(util) ),
            SECURE_CONTEXT_PATH : ( function (utilModule) {
                return location.hostname + ( location.port ? ':' + utilModule.DEFAULT_SECURE_TOMCAT_PORT : '' ) + '/' + ( utilModule.isLocalhost() ? utilModule.WAR_FILE_NAME : '' );
            }(util) )
    }
 
     
    