What is object cloning

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


Please Help Members By Posting Answers For Below Questions

Explain the difference between javascript and an asp script.

506


How can you read properties of an Object in JavaScript?

533


What is require in javascript?

493


Is javascript free to install?

534


Iam getting xml when we click on one button.Iam placing that xml in dom.Im getting that xml data in one xsl.In that xsl I want to increase the variable value which is declared in xsl. Ex: ffftt eeeeiii uuuuwww fff eeee uuuu

1693






What is Number object in JavaScript?

565


What is the function of delete operator?

571


What is an onclick?

521


accessdenied javanet disconnet

1580


How to show progress bar while loading using ajax call?

571


Explain the process of document loading.

503


What is the statement to enable strict mode in javascript quiz?

508


What is the benefit of arrow functions?

473


What is the use of debugger keyword in javascript?

500


What are Cookies in Javascript?

580