How can we assign an object in Java Script??

For Example:-
-----------
If i create an object "obj1"
var obj1 = Object();
obj1.name = "hari";

and if i want to assign it to two objects "obj2" and "obj3"
with different names...

obj1.name = "gopi"
obj2 = new Object(obj1);

obj1.name = "raghu"
obj3 = new Object(obj1)

Now ob2.name become to "raghu" from "gopi". WHY?
how to solve the above problem?

Answer Posted / sandesh magdum

var obj1 = Object();
obj1.name = "hari";

obj1.name = "gopi";
obj2 = new Object(obj1);

//preserving name property of obj2 through obj4
var obj4=new Object();
obj4.name=obj2.name;

obj1.name = "raghu";
obj3 = new Object(obj1);

obj2=new Object(obj4);
alert("obj2 name="+obj2.name+" obj3 name="+obj3.name)

Is This Answer Correct ?    5 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do I handle the back and forward buttons in ajax?

678


Describe how to handle concurrent ajax requests?

731


What is the purpose of xmlhttprequest?

714


What will happen with click of browser "back" button among asynchronous requests?

669


In ajax does the client or the sever have the control?

714


Describe the ajax design pattern.

708


What are the differences between ajax and javascript?

663


How do I abort the current xmlhttprequest?

739


Which are the knowledge requirements for personal ajax functionality?

688


What are ajax controls?

649


Is ajax built into javascript?

681


What does the dynamicpopulateextender control do? : asp.net ajax

701


When will html_ajax have a stable release?

783


How does one call a javascript function from the ajax code?

740


Can I use asp.net ajax with any other technology apart from asp.net?

697