Can destructuring arguments cause inefficiencies if executed thousands of times?
I'm wondering if destructuring my arguments in a react application is efficient. There are many loops over many objects in many layers. How does destructuring work with javascripts pass by reference?
To test this one wrote some coffee. Why is the original updated before the test function is run?
original =
one:
one: 1
two: 2
test = ({one, two}) ->
one.two = two
{one,two}
console.log original # original.one has already beed updated!! see mu's comment.
destructured = test original
console.log destructured is original, original.one is destructured.one
# false true
{
"one": {
"one": 1,
"two": 2
},
"two": 2
}
Destructuring appears to pass by reference. Is this efficient if executed in many many times every time react re renders?
Edit: The unexpected result is well answered by mu in the comments. The question on destructuring being a good practice is the question.