Skip to content

Instantly share code, notes, and snippets.

@dounan
Last active September 19, 2017 01:08
Show Gist options
  • Save dounan/bfb5c1218fa6ce2e858043b01bc7a0a5 to your computer and use it in GitHub Desktop.
Save dounan/bfb5c1218fa6ce2e858043b01bc7a0a5 to your computer and use it in GitHub Desktop.
Sentinel shallow copy gotcha
const obj = {nested: {}};
const wrappedObj = makeSentinel(obj);
// copiedObj is not a sentinel
const copiedObj = {...wrappedObj};
copiedObj.value = "oops"; // mutation is NOT detected
// copiedObj.nested is a sentinel because it was copied from wrappedObj
copiedObj.nested.value = "oops"; // MUTATION DETECTED!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment