Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript .clone problem Reply To: .clone problem

#169424
alisnikol
Participant

Try this,
code the clone by hand properties after properties and check that mutable instances are cloned too.
pro:
– control of what will be performed
– quick execution
cons:
– tedious to write and maintain
– bug prone (copy/paste failure, missing property, reassigned mutable property)

Use reflection:

With your own reflection tools or with an external helper (like jakarta common-beans) it is easy to write a generic copy method that will do the job in one line.
pro:
– easy to write
– no maintenance
cons:
– less control of what happens
– bug prone with mutable object if the reflection tool does not clone sub objects too
– slower execution