Returns a clone, also known as a deep copy, of a variable. Unlike StructCopy
, Duplicate
copies the variable, so there is no reference to the original variable.
Duplicate(variable_name)
Parameter |
Description |
---|---|
variable_name |
The name of a variable to duplicate |
This function is useful in duplicating complex structures, including nested structures and queries.
Note You cannot duplicate a COM, CORBA or JAVA object returned from the cfobject tag or the |
<!--- This example shows the use of Duplicate ---> <html> <head> <title>Duplicate Example</title> </head> <H3>Duplicate Example</H3> <cfset s1 = StructNew()> <cfset s1.nested = StructNew()> <cfset s1.nested.item = "original"> <cfset copy = StructCopy(s1)> <cfset clone = Duplicate(s1)> <!--- modify the original ---> <cfset s1.nested.item = "modified"> <cfoutput> <P>The copy contains the modified value: #copy.nested.item#</P> <P>The duplicate contains the original value: #clone.nested.item#</P> </cfoutput> </body> </html>