Function objects cannot be duplicated by the structured clone algorithm; attempting to throws a DataCloneError exception.
for more information, you can read MDN
if you want to deep clone nested objects, you should make a function to check the type of all of them and copy them one by one.
Lodash deepClone
work with all types, function,s and Symbol copied by reference I suggest that you use Lodash
.
but with the object.assign()
you can do it faster:
const target = { a: () => { return 1 }, b: 2 };
const source = { b: 4, c: 5 };
const returnedTarget = Object.assign(target, source);
console.log(target);
// Expected output: Object { a: 1, b: 4, c: 5 }
console.log(returnedTarget === target);
// Expected output: true
for more information about object cloning you can follow this link