Answer Posted / me
A bit of background information. Because the way memory
works (long story), an object consists of two things, the
reference which is basically a pointer, or a label that is
used to access the object, and the actual object data,
which is stored elsewhere (search Google for explanations
on memory stacks and heaps).
If you would simply copy an object, you would only copy the
reference. So what you end up with, are two references that
point to exactly the same data. When you change the
original object, the copy object gets changed as well, and
visa versa.
If that's not what you want, you have to clone the object,
which means you actually create a new object in memory,
that holds a copy of the data of the original object, and
you also create a new reference that points to this new
object.
When you then change some value in the original object, the
copy object stays unchanged.
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
What does parse Query String return in javascript?
What is argument objects in javascript?
How to have the status line update when the mouse goes over a link (the support of the status line is sporadic)?
Write a program to exaplain the deferred scripts using event handlers in javascript.
What is lazy loading java?
What is the difference between local storage & session storage?
How to convert javascript date to iso standard?
Are java and javascript same?
What is an immediately-invoked function expression?
Explain export & import in javascript?
Can I learn javascript without knowing java?
Is javascript enabled on chrome?
Some XYZ company is arranging for online aptitude tests. Draw detailed E-R diagram for the same..
How to call a function in every x seconds in javascript?
What are JavaScript Cookies?