Created
May 29, 2020 03:52
-
-
Save jhkueh/41496c482e38ac7c84f0b9f3b68dabde to your computer and use it in GitHub Desktop.
function destructuring assigned parameters were not passed by reference
This file contains hidden or 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 a = { a: 1, b: 2, c:3 }; | |
var b = { d: 4, e:5 }; | |
function d1(obj) { | |
obj.a = 5; | |
} | |
d1(a) | |
// a = { a: 5, b: 2, c: 3 } | |
function d2(obj) { | |
obj.c = b; | |
} | |
d2(a) | |
// a = { a: 5, b: 2, c: { d: 4, e:5 } } | |
// function destructuring assigned parameters were not passed by reference | |
function d3({ a, b, c }) { | |
c = 7; | |
} | |
d3(a) | |
// a = { a: 5, b: 2, c: { d: 4, e:5 } } | |
// a.c was not updated |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment