What is object cloning
Answers were Sorted based on User's Feedback
Answer / anurag sharma
loning is a process to copying all fields from one
object
Is This Answer Correct ? | 2 Yes | 0 No |
Answer / 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 |
How to get inner html of an element in javascript?
What looping structures are there in JavaScript?
What are the different types of errors in javascript?
Is there an ide for javascript?
What is rest parameters in javascript?
How can I learn javascript fast?
Is there an alternative to javascript?
What is the Use of true or false in Ajax cal using Java Script?
List html dom mouse events?
How can I request data from the server without reloading the page in the browser?
How we can add title of the page by javascript?
What are arrays in javascript?