ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage   interview questions urls   External Links  Contact Us     Login  |  Sign Up                      
tip   SiteMap shows list of All Categories in this site.
Google
 
Categories >> Software >> Scripts >> Ajax
 
 
 
Question
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?
 Question Submitted By :: Seshumca34
I also faced this Question!!     Rank Answer Posted By  
 
Answer
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)
 
0
Sandesh Magdum
 
View All Answers
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com