As input for a function I get a string scopename like FORM or COOKIE.
How can I access these top level scopes in a bracket notation?
I’m looking for something like:
var myScope = "FORM";
global[myScope];
Obviously that doesn’t work though 🙂
(I’m not looking for any kind of eval function, I’d rather switch through the string manually to get the right scope than an eval function…)
EDIT
Functionality is needed so I can call an easy/accessible function early on in a request to identify bad requests that are either sending the wrong kind of data or are just not sending the required data.
for example I’ll call the following function as early as possible in a request that needs the variables FORM.data1:numeric, FORM.data2:bit and COOKIE.data3:string:
<cfset require({
"FORM" : {
"data1":"numeric",
"data2":"bit"
},
"COOKIE":{
"data3":"string"
}
})>
I’m aware that the following might have been a bit easier:
<cfset require({
"FORM.data1":"numeric",
"FORM.data2":"bit",
"COOKIE.data3":"string"
})>
and than just use isDefined but I need some more flexibility for other functionality.
Well, the simplest solution is just to write it like this:
However, if you find that too verbose, you can use your existing data structure, like this:
Alternatively, there’s an even simpler way of doing it than that:
You imply that you need the unscoped name for other functionality, in which case you simply do
<cfset UnscopedName = ListRest(ArgName,'.') />