I am trying to update an object that is deeply nested and thus has a rather long name that I do not want to keep typing in my code. In this discussion, I shall call it by the shorter name 'target'.
I begin by referring to it by the shorter name 'c':
c = target
I then want to update its contents using another object; call it update
.
If I use c = $.extend(c,update)
, the reference to c remains 'intact'; i.e. c === target
is true.
However, if I use c = {...c, ...update}
, a new variable is created; i.e. c === target
is false. My original target
variable is not updated.
I do not understand why. Can anyone explain?
There is a bin at $extends vs JavaScript spread