Implementation and advanced writing of deep copy

Table Of Contents version one function deepClone(target) { return JSON.parse(JSON.stringify(target)); } const a = { name: "fryao", age: 18 }; const b = deepClone(a); console.log(b); // { name: 'fryao', age: 18} console.log(b === a); // false While this is fine to use most of the time, there are a number of downsides to this approach: If there is a field value in the object that is undefined, the field will disappear directly after conversion If the object has a field value as a RegExp object, the field value will become {} after conversion If the object has a field value of NaN, +-Infinity, the field value becomes null after conversion If the object has a ring reference, the conversion will directly report an error version two Since it is a deep copy of the object, we can create an empty object and copy the values of the original object that need to be copied one by one. function deepClone(target) { if...