structuredClone (deep copy)
Në shqip: Kopja e thellë në JS
ShpjegimiSQ
{...obj} dhe Object.assign() bëjnë vetëm kopje të cekët — objektet brenda mbeten të përbashkëta. structuredClone(obj) bën kopje të plotë, deri në fund, dhe e njeh edhe Date, Map dhe Set.
EnglishEN
{...obj} and Object.assign() only make shallow copies — nested objects stay shared. structuredClone(obj) makes a full, deep copy, and understands Date, Map and Set too.
Si ta mendosh
Kopja e cekët është si ta fotokopjosh vetëm kopertinën e dosjes; structuredClone fotokopjon edhe çdo fletë brenda.
Lexoje në anglisht
A shallow copy is like photocopying just the folder's cover; structuredClone photocopies every sheet inside too.
Shembull kodijavascript
const a = { emri: "Arta", notat: [5, 4] };
const b = structuredClone(a);
b.notat.push(3);
console.log(a.notat); // [5, 4] — e paprekur