Object copy
Syntax
$orig.copy()
copy(orig: $orig,
context: $context,
filter: $filter,
constructor: $constructor,
transient: false)
Description
Creates a deep copy of the object or a simple copy of the value orig
.
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.
Parameters
Name | Type | Description | Mandatory | Default |
---|---|---|---|---|
orig | 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 orig ). |
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 |
no | orig -> reference -> context -> null |
transient |
Boolean | Whether the copy should create a transient object. This option is only relevant if no const function is specified. If nothing is specified (null ), transient objects are copied as transient and persistent ones as persistent. Transient objects are visible only locally in the user's session and cannot be stored in the reference of a persistent object. Conversely, however, a transient object can reference normal persistent objects in its references. |
no | null |
Return Value
Type: Number/string/boolean/business object/set.
Depending on the type of x
the following is returned by the function:
- Reference to a business object: a deep copy of this object.
- list: a list in which all business objects are replaced by deep copies.
- all other values: the value itself.
Examples
Object copy
{
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]
Object list copy
{
a = new(`my.module:MyClass`);
b = new(`my.module:MyClass`);
list = list($a, $b);
$list.copy();
}
Output: A list of copies of the objects a
and b
.
Value copy
{
a = 5;
b = $a.copy();
list($a, $b);
}
Output: A list of values [5, 5] - one time the original number and one time the copied one.