Skip to content

Commit

Permalink
structuredClone is a hypothetical function that deep clones an object
Browse files Browse the repository at this point in the history
  • Loading branch information
asad-raza-dukan committed May 30, 2024
1 parent c25bce8 commit bb12923
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,14 @@ Other Style Guides

// good
const original = { a: 1, b: 2 };
const copy = { ...original, c: 3 }; // copy => { a: 1, b: 2, c: 3 }
const copy = { ...original, c: 3 }; // copy => { a: 1, b: 2, c: 3 } unsuitable for nested object

const { a, ...noA } = copy; // noA => { b: 2, c: 3 }

// best
const original = { a: 1, b: 2 };
// structuredClone is a hypothetical function that deep clones an object
const copy = {...structuredClone(original), c: 3}; // copy => { a: 1, b: 2, c: 3 }

const { a, ...noA } = copy; // noA => { b: 2, c: 3 }
```
Expand Down

0 comments on commit bb12923

Please sign in to comment.