{"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 arr: [{\r\n test: 1\r\n }, {\r\n test: 2\r\n }, {\r\n test: {\r\n a: 1\r\n }\r\n }]\r\n};\r\n\r\nvar myCopy = null;\r\n\r\nfunction simpleCloneDeep(obj) {\r\n if (typeof obj !== \u0027object\u0027 || obj === null) {\r\n return obj;\r\n }\r\n\r\n let result;\r\n if (\r\n (typeof obj.length === \u0027number\u0027 \u0026\u0026 obj instanceof Array) ||\r\n // fix: instanceof Array \u5728IDE\u6A21\u62DF\u5668\u7684iframe\u73AF\u5883\u4E2D\u5224\u65AD\u4E3A false\r\n Object.prototype.toString.call(obj) === \u0027[object Array]\u0027\r\n ) {\r\n const { length } = obj;\r\n result = new Array(length);\r\n for (let i = 0; i \u003C length; i \u002B= 1) {\r\n result[i] = simpleCloneDeep(obj[i]);\r\n }\r\n\r\n return result;\r\n }\r\n\r\n // ios10 \u4E0A\uFF0Cproxy \u5BF9\u8C61 Object.prototype.toString.call(obj)\u8FD4\u56DE \u0027[object,ProxyObject]\u0027\r\n switch (Object.prototype.toString.call(obj)) {\r\n case \u0027[object Map]\u0027:\r\n result = new Map();\r\n obj.forEach((subValue, key) =\u003E {\r\n result.set(key, simpleCloneDeep(subValue));\r\n });\r\n return result;\r\n case \u0027[object Set]\u0027:\r\n result = new Set();\r\n obj.forEach((subValue) =\u003E {\r\n result.add(simpleCloneDeep(subValue));\r\n });\r\n return result;\r\n\r\n default:\r\n result = {};\r\n for (const i in obj) {\r\n if (Object.prototype.hasOwnProperty.call(obj, i)) {\r\n result[i] = simpleCloneDeep(obj[i]);\r\n }\r\n }\r\n\r\n return result;\r\n }\r\n}\r\n","TestCases":[{"Name":"Lodash cloneDeep","Code":"myCopy = _.cloneDeep(MyObject);","IsDeferred":false},{"Name":"Native structuredClone","Code":"myCopy = structuredClone(MyObject);","IsDeferred":false},{"Name":"Simple cloneDeep","Code":"myCopy = simpleCloneDeep(MyObject);","IsDeferred":false}]}