Peg card: objects
You lit up: the flying ships and submarine, and the three reference islands
Remember
- Objects, arrays and functions are ships that store genies (pointers), never the values themselves.
- A variable holding an object sits on a reference rock. Two variables can share one rock - and then they share one ship.
- Changing a ship through one genie changes it for everyone pointing at it.
{ ...obj }clones one level;structuredClone(obj)clones all of them.
Check yourself
Predict both values before you run it.
Spot it in the blog app
viewedPosts is declared with const, and yet this function changes it. How?
Where this fits
Nearly everything in the Universal Pattern is a ship. State lives in objects and arrays, and every element on a web page is an object ship too. The most dangerous bugs in any app are genies quietly mutating a shared ship, so the pattern keeps mutation inside controllers and keeps helpers clean.