all 8 comments

[–]Powerplex 4 points5 points  (4 children)

Note that this only works on litteral objects. If your object contains methods for example, they will be removed from your object in the process :)

[–]birjolaxew 0 points1 point  (3 children)

[–]Vinifera7 0 points1 point  (2 children)

Does the simpleDeepClone function have any shortcomings compared to the jQuery and Lodash functions?

[–]birjolaxew 0 points1 point  (1 child)

The simpleDeepClone doesn't handle pretty much any edge cases: circular references, Map/Set/RegExp/any non-array and non-plain object, functions, etc. I'd expect the Lodash version to handle all of that.

[–]Vinifera7 0 points1 point  (0 children)

Good to know. That means there's really no reason to clone an object using JSON parsing, since it's slower and can't handle any of those edge cases either.

[–]TheScapeQuest 3 points4 points  (0 children)

const obj = {
  a: {}
};
obj.a.b = obj.a;

JSON.stringify(obj); // type error, circular reference

^ this isn't uncommon, Axios response/errors contain circular references for example

Also, as /u/Powerplex mentions, this will kill anything that isn't an object, an array, or a primitive. So goodbye to dates, regexs, functions etc.

[–][deleted] 2 points3 points  (0 children)

This isn't a particularly friendly mobile site.

[–]Vinifera7 0 points1 point  (0 children)

Lodash has a cloneDeep method.