Logo

Programming-Idioms

Create the new object y by cloning the all the contents of x, recursively.
New implementation

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
let y = structuredClone(x);
classes
var
  x,y: TPersistent;
...
  y.assign(x);
...
use v5.7.3;
use Storable qw(dclone);
my $x = [ 1, 2, [ 'a' ], { x => [3,4] } ];

my $y = dclone $x;
import copy
y = copy.deepcopy(x)
y = Marshal.load(Marshal.dump(x))