This is the first day of my participation in Gwen Challenge.

madame

This article mainly introduces JS deep copy shallow copy, deep copy and shallow copy as one of the old regulars in the interview, before preparing for the interview is also according to the back of the interview, but only roughly remember the brief listed, for some more details of the point when asked is still a face.

Common gestures

This is a form of answer that we would normally see in a sutra (no attack, sutra is a summary)

Shallow copy
  1. Expansion operator…
  2. Object.assign
Deep copy

JSON.parse(JSON.stringify(obj))

Disadvantages (slightly more detailed version)
• If obj has a time object, json.stringify will be followed by json.parse and the time will be just a string. Ex :time: "2021-06-01t12:36:32.980z"; • If there are RegExp and Error objects in obj, the serialized result will be empty objects; • If obj has a function called undefined, the serialization result will lose the function or undefined; • Json.stringify () can serialize only the enumerable property of the object, for example, if the object in obj is generated by a constructor, Parse (json.stringify (obj)) deep copy will discard the object's constructor; • Deep copy cannot be correctly implemented if there are circular references in the objectCopy the code

Using json.parse (json.stringify ()) in a project generally does not encounter the above problems (personal opinion). Parse (json.stringify (obj)) points to two memory Spaces by serializing the object to sever the original reference relationship and store it in the new memory space.

At the end

Look often face classics, review knowledge point, still have more or less have a little help, but face classics are brief in general, detailed point still need oneself to see.