Last active
August 29, 2015 14:01
-
-
Save elisechant/e5c51212af5e10e5ab09 to your computer and use it in GitHub Desktop.
Real JavaScript constants
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var config = function() { | |
/** | |
* Set a debug flag | |
* @type {boolean} | |
*/ | |
var DEBUG = true; | |
/** | |
* Set the environment variable | |
* @returns {string} | |
*/ | |
var ENV = function() { | |
switch (window.location.host) { | |
case 'localhost': | |
case 'staging.domain.com': | |
return 'DEV'; | |
break; | |
case 'domain.com': | |
return 'PROD'; | |
break; | |
} | |
return false; | |
}; | |
/** | |
* Getter for Constants | |
* | |
* So we can't access Constants directly and therefore they can't | |
* be overwritten. | |
* | |
* @param constant {String} - variable reference to the Constant | |
*/ | |
var get = function getConstant(constant) { | |
return $.isFunction(constant) ? constant() : constant; | |
}; | |
return { | |
DEBUG: get(DEBUG), | |
ENV: get(ENV) | |
}; | |
}(); | |
console.log(config.ENV); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment