When I initialize an object I want to set this.sound to the current value of Dog.sound.   The code below appears to make this.sound a reference to Dog.sound's value. How can I grab the value instead of a reference?  init: function() {   this.sound = Dog.sound; }
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.
32595
I need to set a constant value as true or false for the particular scenario not sure correct working or not const test = data.findIndex(d =&gt; d.Fname === '' &amp;&amp; d.Lname === '') &lt; 0 ? false : true;  if fname and Lname both are blank then i want to set test as false not sure what is happening here.
27421
In C#, I want to initialize a string value with an empty string.  How should I do this?  What is the right way, and why?  string willi = string.Empty;   or  string willi = String.Empty;   or  string willi = "";   or what?
588
JavaScript allows functions to be treated as objects--if you first define a variable as a function, you can subsequently add properties to that function.  How do you do the reverse, and add a function to an "object"?  This works:  var foo = function() { return 1; }; foo.baz = "qqqq";   At this point, foo() calls the function, and foo.baz has the value "qqqq".  However, if you do the property assignment part first, how do you subsequently assign a function to the variable?  var bar = { baz: "qqqq" };   What can I do now to arrange for bar.baz to have the value "qqqq" and bar() to call the function?
40145
I'm trying to set an attribute inside the init method as .  Component  &lt;aura:component implements="flexipage:availableForAllPageTypes" access="global" &gt;      &lt;aura:handler name="init" value="{!this}" action="{!c.doInit}"/&gt;      &lt;aura:attribute name="canCreateRecord" type="Boolean" default="false" /&gt;       {!v.canCreateRecord} &lt;!-- outputs - false --&gt;  &lt;/aura:component&gt;      Controller  ({     doInit: function(cmp){             cmp.set("v.CanCreateRecord",  true );                             } })   When I output {!v.CanCreateRecord} inside the view, I get the default value of 'false'.     According to , the attribute should be set inside the init function before it is rendered. However, it's not happening in my case. What could I be missing?
23417
I am loading a JavaScript object between Lightning Components   var model = {} model.user = {} model.caller = {} model.caller.name = 'Batman'; model.other = {} // etc   And then into component attributes.  &lt;aura:attribute name="model" type="Object" /&gt; &lt;aura:attribute name="caller" type="Object" /&gt;  cmp.set("v.model", model); cmp.set("v.caller", model.caller);   Then I use then like this:  &lt;lightning:input value="{!v.caller.name }" label="Caller name" /&gt;   Then I get data back out:  model.caller = cmp.get("v.caller");      My question is:  Why do my JavaScript object sub-objects sometimes get set to Proxy when I inspect them in the console:  caller: Proxy [[Handler]]: e [[Target]]: Object [[IsRevoked]]: false   And other times I get the values I expect...  caller { name : "Bruce Wayne" }
45838
If I have the following code:  MyClass pClass = new MyClass(); pClass.MyEvent += MyFunction; pClass = null;   Will pClass be garbage collected? Or will it hang around still firing its events whenever they occur? Will I need to do the following in order to allow garbage collection?  MyClass pClass = new MyClass(); pClass.MyEvent += MyFunction; pClass.MyEvent -= MyFunction; pClass = null;
54835
I'm used to writing classes like this:  public class foo {   private string mBar = "bar";   public string Bar {     get { return mBar; }     set { mBar = value; }   }   //... other methods, no constructor ... }   Converting Bar to an auto-property seems convenient and concise, but how can I retain the initialization without adding a constructor and putting the initialization in there?  public class foo2theRevengeOfFoo {   //private string mBar = "bar";   public string Bar { get; set; }   //... other methods, no constructor ...   //behavior has changed. }   You could see that adding a constructor isn't inline with the effort savings I'm supposed to be getting from auto-properties.  Something like this would make more sense to me:  public string Bar { get; set; } = "bar";
118610
I remember seeing a while ago that there is some method in maybe the Reflection namespace that would recursively run ToString() on all of an object's properties and format it nicely for display.    Yes, I know everything I could want will be accessible through the debugger, but I'm wondering if anyone knows that command?
8925
Suppose I have a python object x and a string s, how do I set the attribute s on x? So:  &gt;&gt;&gt; x = SomeObject() &gt;&gt;&gt; attr = 'myAttr' &gt;&gt;&gt; # magic goes here &gt;&gt;&gt; x.myAttr 'magic'   What's the magic? The goal of this, incidentally, is to cache calls to x.__getattr__().
44431
Could you explain the difference between setting methods in the constructor and through prototype object? The following code shows these two ways of setting the methods - say_hello and say_bye both work fine:  function MessageClass() {   this.say_bye = function() { alert('see ya'); }; }  MessageClass.prototype.say_hello = function() { alert('hello'); };  x = new MessageClass(); x.say_hello(); x.say_bye();
27026
Something like  var life= {         users : {              guys : function(){ this.SOMETHING.mameAndDestroy(this.girls); },              girls : function(){ this.SOMETHING.kiss(this.boys); },         },         mameAndDestroy : function(group){ },         kiss : function(group){ } };   this.SOMETHING is what I imagine the format is, but it might not be. What will step back up to the parent of an object?
30201
How do I pass data between hooks that don't interact between them, or between a menu callback and a hook?  In the case the two hooks have a parameter in common, and that parameter is passed by reference, that is easy. What do I do when the hooks, or the menu callback and the hook, don't get a common parameter?
34071
Consider this:  public class TestClass {      private String a;     private String b;      public TestClass()     {     a = "initialized";     }      public void doSomething()     {     String c;          a.notify(); // This is fine     b.notify(); // This is fine - but will end in an exception     c.notify(); // "Local variable c may not have been initialised"     }  }   I don't get it. "b" is never initialized but will give the same run-time error as "c", which is a compile-time error. Why the difference between local variables and members?  Edit: making the members private was my initial intention, and the question still stands...
22006
When defining a method on a class in Python, it looks something like this:  class MyClass(object):     def __init__(self, x, y):         self.x = x         self.y = y   But in some other languages, such as C#, you have a reference to the object that the method is bound to with the "this" keyword without declaring it as an argument in the method prototype.    Was this an intentional language design decision in Python or are there some implementation details that require the passing of "self" as an argument?
330
The primitive types (number, string, etc.) are passed by value, but objects are unknown, because they can be both passed-by-value (in case we consider that a variable holding an object is in fact a reference to the object) and passed-by-reference (when we consider that the variable to the object holds the object itself).  Although it doesn't really matter at the end, I want to know what is the correct way to present the arguments passing conventions. Is there an excerpt from JavaScript specification, which defines what should be the semantics regarding this?
118657
When {0} is used to initialize an object, what does it mean? I can't find any references to {0} anywhere, and because of the curly braces Google searches are not helpful.  Example code:  SHELLEXECUTEINFO sexi = {0}; // what does this do? sexi.cbSize = sizeof(SHELLEXECUTEINFO); sexi.hwnd = NULL; sexi.fMask = SEE_MASK_NOCLOSEPROCESS; sexi.lpFile = lpFile.c_str(); sexi.lpParameters = args; sexi.nShow = nShow;  if(ShellExecuteEx(&amp;sexi)) {     DWORD wait = WaitForSingleObject(sexi.hProcess, INFINITE);     if(wait == WAIT_OBJECT_0)         GetExitCodeProcess(sexi.hProcess, &amp;returnCode); }   Without it, the above code will crash on runtime.