dup

Create a duplicate of a thing.

The function preserves the Type of a thing. Use copy(..) to copy into a plain thing.

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.

Function

thing.dup([deep]])

Arguments

Argument Type Description
deep int (optional) How deep to duplicate the thing. Default is 1.

Return value

A new thing.

Example

This code shows an example using dup():

a = {x: 123};
b = a.dup();

// `b` is a duplicate, so `a.x` will not change
b.x = 456;

[a.x, b.x];

Return value in JSON format

[
    123,
    456
]

Note that a duplicate keeps the Type information:

set_type('Person', {
    name: 'str'
});

p = Person{
    name: 'Foo'
};

o = p.dup();

type(o);  // type `Person`

Return value in JSON format

"Person"