Hi,
nice post, but i'd like you to note that there are some difference between deepClone and JSON.stringify/parse.
JSON.stringify/parse only work with Number and String and Object litteral without function or Symbol properties.
deepClone work with all types, function and Symbol are copied by reference.
Here an example:
constlodashClonedeep=require("lodash.clonedeep");constarrOfFunction=[()=>2,{test:()=>3,},Symbol('4')];// deepClone copy by refence function and Symbolconsole.log(lodashClonedeep(arrOfFunction));// JSON replace function with null and function in object with undefinedconsole.log(JSON.parse(JSON.stringify(arrOfFunction)));// function and symbol are copied by reference in deepCloneconsole.log(lodashClonedeep(arrOfFunction)[0]===lodashClonedeep(arrOfFunction)[0]);console.log(lodashClonedeep(arrOfFunction)[2]===lodashClonedeep(arrOfFunction)[2]);
Hi,
nice post, but i'd like you to note that there are some difference between deepClone and JSON.stringify/parse.
Here an example:
Exactly! Thanks for sharing this! Let me add it to my code notes 👍