Created
December 3, 2015 16:42
-
-
Save ultimapanzer/b4378d10e559d30bb0a3 to your computer and use it in GitHub Desktop.
spread doesn't mutate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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