{"ScriptPreparationCode":"var MyObject = {\r\n description: \u0027Creates a deep copy of source, which should be an object or an array.\u0027,\r\n myNumber: 123456789,\r\n myBoolean: true,\r\n jayson: {\r\n stringify: \u0027JSON.stringify() method converts a JavaScript value to a JSON string....\u0027,\r\n parse: \u0027JSON.parse() method parses a JSON string...\u0027\r\n }\r\n};\r\n\r\nvar myCopy = null;\r\n\r\nfunction cloneDeep(entity, cache = new WeakMap) {\r\n const referenceTypes = [\u0027Array\u0027, \u0027Object\u0027, \u0027Map\u0027, \u0027Set\u0027, \u0027Date\u0027];\r\n const entityType = Object.prototype.toString.call(entity);\r\n if (\r\n !new RegExp(referenceTypes.join(\u0027|\u0027)).test(entityType) ||\r\n entity instanceof WeakMap ||\r\n entity instanceof WeakSet\r\n ) return entity;\r\n if (cache.has(entity)) {\r\n return cache.get(entity);\r\n }\r\n const c = new entity.constructor;\r\n \r\n if (entity instanceof Map) {\r\n entity.forEach((value, key) =\u003E c.set(cloneDeep(key), cloneDeep(value)));\r\n }\r\n if (entity instanceof Set) {\r\n entity.forEach((value) =\u003E c.add(cloneDeep(value)));\r\n }\r\n if (entity instanceof Date) {\r\n return new Date(entity);\r\n }\r\n cache.set(entity, c);\r\n return Object.assign(c, ...Object.keys(entity).map((prop) =\u003E ({ [prop]: cloneDeep(entity[prop], cache) })));\r\n}\r\n","TestCases":[{"Name":"Lodash cloneDeep","Code":"myCopy = _.cloneDeep(MyObject);","IsDeferred":false},{"Name":"Json clone","Code":"myCopy = JSON.parse(JSON.stringify(MyObject));","IsDeferred":false},{"Name":"freeze and destructure","Code":"Object.freeze(MyObject); myCopy = { ...MyObject };","IsDeferred":false},{"Name":"Vanilla cloneDeep","Code":"myCopy = cloneDeep(MyObject)","IsDeferred":false}]}