Just as a matter of interest, a cludge I put together utilising JScript Closures to provides access to constant, unchangeable values.
// Module that provides access to Constant, unchangeable, values
var constant = (function() {
// The Constant values, as these are in a Closure, they
// cannot be changed unless a method was to be provided
var CONST = "I am Constant",
CONST_TWO = "As am I";
return {
// Returns the value of the Constant specified by the name parameter
value: function( name ) {
try {
// Use our friend eval to get the constant value as we referencing it by
// a String. We can't just use eval( "return " + name ); as it will throw a
// "'return' statement outside of function" exception
eval( "var val = " + name );
return val;
} catch( e ) {
// Specified Constant does not exist so just return null
return null;
}
}
}
})();
// Tests the constant Module
function testConstant() {
var s = constant.value( "CONST" );
Log.Message( s ); // Logs I am Constant
Log.Message( constant.value( "CONST_TWO" ) ); // Logs As am I
Log.Message( constant.value( "DOES_NOT_EXIST" ) ); // Logs a null String
}
It may be of interest to someone.
Regards,
Phil Baird