Is there any "short" syntax for creating a struct in ColdFusion? I'd like to replace this verbose code:
<cfscript>
ref = StructNew();
ref.Template = "Label";
ref.Language = "en";
stcML = GetPrompts(ref);
</cfscript>
with something more like a JavaScript object:
<cfscript>
stcML = GetPrompts({ Template: "Label", Language: "en" });
</cfscript>
Is there anything like this?
Coldfusion 8 (and up) has a struct literal notation:
<cfset objData = {
Key1 = "Value1",
Key2 = "Value2"
}>
However, there are a few strings attached:
Note: ColdFusion 9 fixed the errors outlined above, so with any CF version available nowadays you will be fine. I'm still leaving in the links for reference.
Starting with CF10, you can also use the syntax that's familiar from JavaScript:
<cfset objData = {
Key1: "Value1",
Key2: "Value2"
}>