Whatever message this page gives is out now! Go check it out!
Duplicate(object)Parameter | Type | Description |
object | Name of a variable to duplicate | |
| deepCopy | Boolean | If deepCopy is TRUE, the child elements are cloned. If deepCopy is FALSE, child elements remain linked to their respective elements in the original object. |
<cfscript>
s1 = StructNew()
s1.nested = StructNew()
s1.nested.item = "original"
copy = StructCopy(s1)
clone = Duplicate(s1)
// modify the original struct
s1.nested.item = "modified"
writeOutput("The copy contains the modified value: " & copy.nested.item & "<br/>")
writeOutput("The duplicate contains the original value: " & clone.nested.item)
</cfscript><cfscript>
originalStruct = {
name = "Alice",
address = {
street = "123 Main St",
city = "Wonderland"
},
mobile = 7777777777
}
// Create a deep & a shallow copy
deepCopy = duplicate(originalStruct);
shallowCopy = duplicate(originalStruct, true);
// Modify a nested property in the original struct
originalStruct.address.street = "456 Oak St";
// Display results
writeOutput(#deepCopy.address.street#& "<br/>"); // deep copy
writeOutput(#shallowCopy.address.street#); // shallow copy
</cfscript><cfscript>
originalStruct = {
name = "Alice",
address = {
street = "123 Main St",
city = "Wonderland"
},
mobile = 7777777777
}
// Create a deep & a shallow copy
deepCopy = duplicate(originalStruct);
shallowCopy = duplicate(originalStruct, false);
// Modify a nested property in the original struct
originalStruct.address.street = "456 Oak St";
// Display results
writeOutput(#deepCopy.address.street#& "<br/>"); // deep copy
writeOutput(#shallowCopy.address.street#); // shallow copy
</cfscript>