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

Is ajax an api?

501


Describe the accordionextender control?

537


What is the difference between proxied and proxyless calls?

540


Would we be able to call server-side code from javascript?

500


Is there any use abilities problems in ajax?

625






is the xmlhttprequest object part of a w3c standard?

578


What is asynchronous request in ajax?

536


Is it compulsory to have script manager on the page when you are using any control of ajax control tool kit?

538


How to cancel the current request in ajax?

540


What is xmlhttprequest object in ajax?

608


What is xmlhttprequest object in ajax? How can you xmlhttprequest object?

517


How do we get the xmlhttprequest object?

595


What are the ajax security issues?

494


What are the tools for debugging ajax applications?

521


What parts of the html_ajax api are stable?

547