Copy a thing.
The function does not preserve the Type of a thing. Use dup(..) if you want a copy of the same type.
For the deep value, this function does not inherit the current deep value but always uses 1
as default.
This function does not generate a change.
thing.copy([deep]])
Argument | Type | Description |
---|---|---|
deep | int (optional) | How deep to copy the thing. Default is 1 . |
A new thing.
This code shows an example using copy():
a = {x: 123};
b = a.copy();
// `b` is a copy, so `a.x` will not change
b.x = 456;
[a.x, b.x];
Return value in JSON format
[
123,
456
]
Note that a copy is a new thing and Type information will be lost:
set_type('Person', {
name: 'str'
});
p = Person{
name: 'Foo'
};
o = p.copy();
type(o); // just a normal `thing`
Return value in JSON format
"thing"