$object.copy()
$object.copy($context, $filter, $constructor)
Creates a deep copy of the object or a simple copy of the value object.
In a deep copy of an object, all objects reachable via composition references are also copied. Other references in the copied object graph are transposed to objects in the new graph if they pointed in the original graph to an object that was copied along with the copy operation.
| Name | Type | Description | Mandatory | Default |
|---|---|---|---|---|
| object | Number/string/boolean/business object/set | The object or value to be copied. | yes | |
| context | Business object | The context object that will be passed when creating the top-level copy (from object). |
no | null |
| filter | Function | Decides whether a particular property should be copied along from the source graph. The filter function receives three arguments.
If the decision is If the decision is |
no | attribute -> orig -> context -> true |
| constructor | Function | A function that takes an object from the source graph and returns an (uninitialized) copy of that object. The function receives three arguments:
If the constructor function returns |
no | orig -> reference -> context -> null |
Type: Number/string/boolean/business object/set
Depending on the type of x, the following is returned by the function:
{
a = new(`my.module:MyClass`);
$a.set(`my.module:MyClass#name`, "orig");
b = $a.copy();
$b.set(`my.module:MyClass#name`, "copy");
list($a, $b);
}
Output: Outputs a list with the original and the copied object: [orig, copy]
{
a = new(`my.module:MyClass`);
b = new(`my.module:MyClass`);
list = list($a, $b);
$list.copy();
}
Output: A list with copies of the objects a and b.
{
a = 5;
b = $a.copy();
list($a, $b);
}
Output: A list with the values [5, 5] - one time the original number and one time the copied one.