I want to create new json object from exiting one, because if I create from   var person1= { First Name: 'John',   Last Name: 'Smith',   age: 54,   dateofbirth: '31-08-68',  } var person2=person1; delete person2.age   This will also delete age from the person1, I don't want to delete age from person1, but person2. Because I need to initialize other person also. So How I create new json object from exiting object .
912
What is the most efficient way to clone a JavaScript object? I've seen obj = eval(uneval(o)); being used, but . I've done things like obj = JSON.parse(JSON.stringify(o)); but question the efficiency.  I've also seen recursive copying functions with various flaws.  I'm surprised no canonical solution exists.
29493
I'm in the process of writing a piece of code that connects to a server spawns a bunch of threads using that connection and does a bunch of "stuff".  There are certain instances where the connection fails and I need to stop everything and start from scratch with a new object.  I wanted to clean up after the object but calling thread.stop on the threads, but this method is seemingly deprecated.  What is the recommended alternative to doing this? Should I write my own cleanup and exit method for each of the threads? Set the thread to null? or something else?
38193
A type of the body is JSON Blob in a form of:  {"key1":"val1";"key2":"val2"}  I wanted to convert it into a Map&lt;String, String&gt;. Do I have to manually deserialize it or there's a class which can handle that?
44986
I have a String representation of a date that I need to create a Date or Calendar object from. I've looked through Date and Calendar APIs but haven't found anything that can do this other than creating my own ugly parse method. I know there must be a way, does anyone know of a solution?
93096
How can I create an  using python? I'd like to create one for each selected object and then all empties should be parented or constraint to the selected objects, meaning that the rotation and position should be copied over as well. I tried something along these lines but I can't get it to work properly: import bpy  for obj in bpy.context.selected_objects:     bpy.ops.object.empty_add()  Q: How to create an empty per object in selection?
38591
class someclass {};  class base {     int a;     int *pint;     someclass objsomeclass;     someclass* psomeclass; public:     base()     {         objsomeclass = someclass();         psomeclass = new someclass();         pint = new int();          throw "constructor failed";         a = 43;     } }  int main() {     base temp(); }   In the above code, the constructor throws. Which objects will be leaked, and how can the memory leaks be avoided?  int main() {     base *temp = new base(); }   How about in the above code? How can the memory leaks be avoided after the constructor throws?
614
I need to be able to merge two (very simple) JavaScript objects at runtime.  For example I'd like to:  var obj1 = { food: 'pizza', car: 'ford' } var obj2 = { animal: 'dog' }  obj1.merge(obj2);  //obj1 now has three properties: food, car, and animal   Does anyone have a script for this or know of a built in way to do this?  I do not need recursion, and I do not need to merge functions, just methods on flat objects.
38527
I'm just trying to streamline one of my classes and have introduced some functionality in the same style as the .  However, I'm a bit confused as to why __init__ is always called after __new__. I wasn't expecting this. Can anyone tell me why this is happening and how I can implement this functionality otherwise? (Apart from putting the implementation into the __new__ which feels quite hacky.)  Here's an example:  class A(object):     _dict = dict()      def __new__(cls):         if 'key' in A._dict:             print "EXISTS"             return A._dict['key']         else:             print "NEW"             return super(A, cls).__new__(cls)      def __init__(self):         print "INIT"         A._dict['key'] = self         print ""  a1 = A() a2 = A() a3 = A()   Outputs:  NEW INIT  EXISTS INIT  EXISTS INIT   Why?
95768
Is there any way in javascript to create a "weak reference" to another object?   Can anyone think of a way to implement this  behavior in javascript?
81320
I am trying to add key value pair in the below JSON object, but it is getting added in the wrong way, is there any way i can add to each object a new  key value pair, that will help me to complete the req. JSON as follow : var object =[       {          &quot;asdf&quot;:&quot;&quot;,          &quot;fdrtf&quot;:&quot;869966&quot;,          &quot;hdhfhfh&quot;:&quot;utytut&quot;,          &quot;Cat&quot;:&quot;A&quot;                 },       {          &quot;hjhj&quot;:&quot;&quot;,          &quot;hfhfhf&quot;:&quot;h&quot;,          &quot;hhfh&quot;:&quot;hfjfhdj&quot;,          &quot;cat&quot;:&quot;B&quot;                 },       {          &quot;hjhj&quot;:&quot;&quot;,          &quot;hfhfhf&quot;:&quot;h&quot;,          &quot;hhfh&quot;:&quot;hfjfhdj&quot;,          &quot;cat&quot;:&quot;B&quot;       } ]  code i am using to add the new key value pair : for (let i = 0; i &lt; object.length; i++) {             object[i]['ABC'] = [i];         }  Actually expected should be: var object =[       {          &quot;asdf&quot;:&quot;&quot;,          &quot;fdrtf&quot;:&quot;869966&quot;,          &quot;hdhfhfh&quot;:&quot;utytut&quot;,          &quot;Cat&quot;:&quot;A&quot;,          &quot;ABC&quot;: &quot;0&quot;                 },       {          &quot;hjhj&quot;:&quot;&quot;,          &quot;hfhfhf&quot;:&quot;h&quot;,          &quot;hhfh&quot;:&quot;hfjfhdj&quot;,          &quot;cat&quot;:&quot;B&quot;,          &quot;ABC&quot;: &quot;1&quot;                 },       {          &quot;hjhj&quot;:&quot;&quot;,          &quot;hfhfhf&quot;:&quot;h&quot;,          &quot;hhfh&quot;:&quot;hfjfhdj&quot;,          &quot;cat&quot;:&quot;B&quot;          &quot;ABC&quot;: &quot;2&quot;       } ]  the final value i am getting as below: [&quot;0&quot;:{          &quot;hjhj&quot;:&quot;&quot;,          &quot;hfhfhf&quot;:&quot;h&quot;,          &quot;hhfh&quot;:&quot;hfjfhdj&quot;,          &quot;cat&quot;:&quot;B&quot;,           },    &quot;1&quot;:{          &quot;asdf&quot;:&quot;&quot;,          &quot;fdrtf&quot;:&quot;869966&quot;,          &quot;hdhfhfh&quot;:&quot;utytut&quot;,          &quot;Cat&quot;:&quot;A&quot;              },    &quot;2&quot;:{        &quot;hjhj&quot;:&quot;&quot;,          &quot;hfhfhf&quot;:&quot;h&quot;,          &quot;hhfh&quot;:&quot;hfjfhdj&quot;,          &quot;cat&quot;:&quot;B&quot;    }   ]  kindly someone help me out to achieve this
12281
I entered this statement in JSLint:  var number = new Number(3);   And received the following message:     Do not use Number as a constructor.   Why is that? The statement is creating a number object, not a primitive value, so I don't see why using new is a problem.  EDIT: Thanks for all the responses. They've got me thinking further, so I posted a follow-up question .
38893
I prefer to use OOP in large scale projects like the one I'm working on right now. I need to create several classes in JavaScript but, if I'm not mistaken, there are at least a couple of ways to go about doing that. What would be the syntax and why would it be done in that way?  I would like to avoid using third-party libraries - at least at first. Looking for other answers, I found the article  that discusses object-oriented programming in JavaScript. Is there a better way to do inheritance?
109761
I have getting the below JSON on using JSON.serialize  [ {   "lname" : "Singh",   "hcpZipCode" : null,   "hcpState" : null,   "hcpEmail" : "test@test.com",   "hcpCity" : null,   "hcpAddLine1" : null,   "fname" : "Abhey",   "countryCode" : "AUS" } ]   I don't know why this '[' is coming at the begining.I don't need this '[' at the begining due to which I am getting System.JSONException: Malformed JSON: Expected '{' at the beginning of object  code     public PageReference step2() {         string JSONstr='';        List&lt;HCPRequest&gt; conWrapList = new List&lt;HCPRequest&gt;();        HCPRequest tempcontactWrapper = new HCPRequest();        tempcontactWrapper.fname='Abhey';        tempcontactWrapper.lname='Singh';        tempcontactWrapper.countryCode='AUS';        tempcontactWrapper.hcpEmail=contact.Email;         conWrapList.add(tempcontactWrapper);          JSONstr = JSON.serializePretty(conWrapList);         System.debug('\n******'+JSONstr +'\n******');          String clientId = 'xy';         String clientSecret = 'x';          //We can also store our username password in custom setting.         String username='x';//salesforce username          String password='x';//password+securitytoken         // Generating the Access Token         HttpRequest req = new HttpRequest();         req.setMethod('POST');         req.setEndpoint('https://test.salesforce.com/services/oauth2/token');// this is the OAuth endpoint where this request will be hit         req.setBody('grant_type=password&amp;client_id='+clientId+'&amp;client_secret='+clientSecret+'&amp;username='+username+'&amp;password='+password);          Http http = new Http();         HTTPResponse res = http.send(req);         String str = res.getBody();         wrapObj = (Wrapper)Json.deserialize(str,Wrapper.class);         accessToken = wrapObj.access_token;         instanceUrl = wrapObj.instance_url;          HttpRequest req1 = new HttpRequest();         string response='';         req1.setMethod('POST');         //req.setEndpoint(wrapObj.instance_url+'/services/apexrest/Account/getAccountById?name=champaKAli');         string EndPt = 'y';         string email='test@test.com';         req1.setEndpoint(EndPt);         req1.setHeader('Authorization', 'OAuth '+wrapObj.access_token);          req1.setHeader('Content-Type', 'application/json');          //req1.setBody('{"request":{"lname" : "Singh","hcpZipCode" : null,"hcpState" : null,"hcpEmail" : "test@test.com","hcpCity" : null,"hcpAddLine1" : null,"fname" : "Abhey","countryCode" : "AUS"}}');          req1.setBody('{"request":'+JSON.Serialize(conWrapList)+'}');          //req.setBody('{"request": {"countryCode": "AUS","hcpEmail" : ""+email}}');          //req.setTimeout(60000);             //req.setHeader('Content-Length', '0');         Http http1 = new Http();         HTTPResponse res1 = http1.send(req1);          System.debug('***Response***** ' + res1.getBody());         if(res1.getBody()!=null)         {             response=res1.getBody();             HCPResponse saj=(HCPResponse)JSON.deserialize(response,HCPResponse.class);           System.debug('***Response came full***** ' + saj);            System.debug('***Response came***** ' + saj.accList);             for(HCPResponseDetail s :saj.accList)            {            System.debug('***Response email***** ' + s.hcpEmail);            System.debug('***Response add2***** ' + s.hcpAddrLine2);            contact.Address1_Line2__c=s.hcpAddrLine2;            }           //return response;         //string methodcall=methodGet(JSONstr);               return Page.opptyStep2CustomReg;         }
27944
I know how to successfully duplicate an object by using  bpy.ops.object.add_named(name = 'TemplateObjectName')   If the template object named 'TemplateObjectName' has animations, particle systems and modifiers attached to it, the previous call will create a duplicate object that also has those components. However, if I duplicate an object using   template_object = bpy.data.objects['TemplateObjectName'] new_object = bpy.data.objects.new('NewObjectName', template_object.data) collection.objects.link(new_object)   how do I attach the template object's animation, modifiers, particle systems...?
118853
I am really confused what is @id used for in json-ld syntax. Sample from apple.com. What does @id actually represent. Any help would be great?  &lt;script type="application/ld+json"&gt; {     "@context": "http://schema.org",     "@id": "http://www.apple.com/#organization",     "@type": "Organization",     "url": "http://www.apple.com/",     "logo": "https://www.apple.com/ac/structured-data/images/knowledge_graph_logo.png?201608191052",     "contactPoint": [         {             "@type": "ContactPoint",             "telephone": "+1-800-692-7753",             "contactType": "sales",             "areaServed": [ "US" ]         }     ],     "sameAs": [         "http://www.wikidata.org/entity/Q312",         "https://www.youtube.com/user/Apple",         "https://www.linkedin.com/company/apple"     ] }
89
I'm not that into dynamic programming languages but I've written my fair share of JavaScript code. I never really got my head around this prototype-based programming, does any one know how this works? var obj = new Object(); obj.prototype.test = function() { alert('Hello?'); }; var obj2 = new obj(); obj2.test();  I remember a lot discussion I had with people a while back (I'm not exactly sure what I'm doing) but as I understand it, there's no concept of a class. It's just an object, and instances of those objects are clones of the original, right? But what is the exact purpose of this &quot;.prototype&quot; property in JavaScript? How does it relate to instantiating objects? Update: correct way var obj = new Object(); // not a functional object obj.prototype.test = function() { alert('Hello?'); }; // this is wrong!  function MyObject() {} // a first class functional object MyObject.prototype.test = function() { alert('OK'); } // OK  Also these  really helped a lot.
23131
What is the best way to convert a JSON code as this:  {      "data" :      {          "field1" : "value1",          "field2" : "value2"     } }   in a Java Map in which one the keys are (field1, field2) and the values for those fields are (value1, value2).  Any ideas? Should I use Json-lib for that? Or better if I write my own parser?