I am trying to setup a constants file for one of my sites. I am trying to set it up so I can get string constants when needed.
What I have so far (Not working, kind of C# ish)
var Constants = new SiteConstants();
function SiteConstants()
{
this.Training = function Training()
{
this.Staff = function Staff()
{
this.fetch = "someurl";
}
}
}
console.log(Constants.Training().Staff().fetch); //Fail - what i want to call
//or something similar like Constants.Training.Staff.fetch
console.log((new Constants.Staff()).fetch); //Success
Is this possible in JavaScript, and if not, can someone suggest an alternative?
(new (new Constants.Training()).Staff()).fetchconstkeyword (developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…) but I wouldn't suggest it since it isn't widely supported yet. And I think it's pretty obvious what the OP means by "constants", and object literals, as you suggest, are probably the best way to go...constis a reserved word but not presently implemented in the ECMAScript spec, to my knowledge. The OP was confusing because it used a word that has a specific meaning in an unclear way.