Skip to content

Instantly share code, notes, and snippets.

@ultimapanzer
Created December 3, 2015 16:42
Show Gist options
  • Save ultimapanzer/b4378d10e559d30bb0a3 to your computer and use it in GitHub Desktop.
Save ultimapanzer/b4378d10e559d30bb0a3 to your computer and use it in GitHub Desktop.
spread doesn't mutate
var foo = { a: 1, b: 2 };
var bar = foo;
bar.c = 3;
console.log(bar); //=> { a:1, b:2, c:3 }
console.log(foo); //=> { a:1, b:2, c:3 } foo was mutated
//however
foo = { a: 1, b: 2};
var baz = {...foo};
baz.c = 3;
console.log(baz); //=> { a:1, b:2, c:3 }
console.log(foo); //=> { a:1, b:2 } foo wasn't mutated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment