Basically the code says everything. I have a variable x with a css property. I'm saving all the css of x into y, and then I change the value of the y's property. This change also affects x, why? How to make it to only pass the value so that x stays unchanged?  var x = {}; x.css = {height: 100, width: 100};  var y = {}; y.css = x.css; y.css.height = 200;  console.log(x.css.height); //equals to 200 while it should be 100
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?
123912
Recently I wrote a bit of Lua code something like:  local a = {} for i = 1, n do    local copy = a    -- alter the values in the copy end   Obviously, that wasn't what I wanted to do since variables hold references to an anonymous table not the values of the table themselves in Lua.  This is clearly laid out in , but I'd forgotten about it.  So the question is what should I write instead of copy = a to get a copy of the values in a?
37877
I have an image URL in a imageUrl variable and I am trying to set it as CSS style, using jQuery:  $('myObject').css('background-image', imageUrl);   This seems to be not working, as:  console.log($('myObject').css('background-image'));   returns none.  Any idea, what I am doing wrong?
67748
I have a simple html block like:  &lt;span id="replies"&gt;8&lt;/span&gt;   Using jquery I'm trying to add a 1 to the value (8).  var currentValue = $("#replies").text(); var newValue = currentValue + 1; $("replies").text(newValue);   What's happening is it is appearing like:  81  then  811  not 9, which would be the correct answer.  What am I doing wrong?
69666
How can I easily detect when a variable changes value? I would like the execution of the program to break on the debugger whenever a specified variable changes value. Right now I'm using Eclipse's debugger.
29285
What's the difference between &lt;div class=""&gt; and &lt;div id=""&gt; when it comes to CSS? Is it alright to use &lt;div id=""&gt;?  I see different developers doing this in both ways, and since I'm self taught, I've never really figured it out.
73942
Can someone explain to me how XOR swapping of two variables with no temp variable works?  void xorSwap (int *x, int *y) {     if (x != y) {         *x ^= *y;         *y ^= *x;         *x ^= *y;     } }   I understand WHAT it does, but can someone walk me through the logic of how it works?
4495
How do I check if an object has a specific property in JavaScript?  Consider:  x = {'key': 1}; if ( x.hasOwnProperty('key') ) {     //Do this }   Is that the best way to do it?
43780
I want to pass the java-script value to controller.I am using repeat on VF page.  VF page      &lt;apex:repeat value="{!listAdj}" var="Adj" id="hrs"&gt;       &lt;td&gt;&lt;div class="requiredInput"&gt;&lt;div class="requiredBlock"&gt;&lt;/div&gt;     &lt;apex:inputField id="decimal" value="{!Adj.Hours_Decimal__c}" onchange="setHidden5(this);" &gt;       &lt;/apex:inputField&gt;     &lt;/div&gt;&lt;/td&gt;             &lt;apex:inputField id="hours" value="{!Adj.Hours__c}" /&gt; &lt;apex:inputField id="decimal" value="{!Adj.Hours_Decimal__c}" onchange="setHidden5(this);"/&gt;              &lt;/apex:repeat&gt;   Javascript code  function setHidden5(element){     //split the id of the inputField by ':' and then use the 5th index in the array to exact position of the inputField in the apex:repeat.   var idArray = element.id.split(':');     var hiddenRep1 =document.getElementById("thePage:form:hrs:hrs:"+idArray[4]+":decimal");          var hiddenRep2 = document.getElementById("thePage:form:hrs:hrs:"+idArray[4]+":hours");       if(element.value.length &gt;=1){        document.getElementById("thePage:form:hrs:hrs:"+idArray[4]+":hours").disabled = true; **hiddenRep2.value=hidden1.value;**                }                             }     }   I want to pass the hiddenRep2.value to controller.How to pass that. Hidden2.value is same as hidden1.value + some addition subtraction.i dont know how to pass that value. Can someone me sort out this.  Thanks
14541
I have a pretty good understanding of Javascript, except that I can't figure out a nice way to set the "this" variable.  Consider:  var myFunction = function(){     alert(this.foo_variable); }  var someObj = document.body; //using body as example object someObj.foo_variable = "hi"; //set foo_variable so it alerts  var old_fn = someObj.fn;   //store old value someObj.fn = myFunction;   //bind to someObj so "this" keyword works someObj.fn();               someObj.fn = old_fn;       //restore old value   Is there a way to do this without the last 4 lines?  It's rather annoying...  I've tried   binding an anonymous function, which I thought was beautiful and clever, but to no avail:  var myFunction = function(){     alert(this.foo_variable); }  var someObj = document.body;        //using body as example object someObj.foo_variable = "hi";        //set foo_variable so it alerts someObj.(function(){ fn(); })();    //fail.   Obviously, passing the variable into myFunction is an option... but that's not the point of this question.  Thanks.
102377
Assuming there are 5 items in the settings file (MySetting1 to MySetting5), why does PropertyValues have 0 items while Properties has the correct number?   Console.WriteLine( Properties.Settings.Default.PropertyValues.Count); // Displays 0 Console.WriteLine( Properties.Settings.Default.Properties.Count);     // Displays 5
6852
What is the difference between below variables assignments?   var=23 var =23 var= 23 var = 23   Is there any difference in space around the assignment operator?
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?
8401
I have a drop-down list with known values. What I'm trying to do is set the drop down list to a particular value that I know exists using jQuery.  Using regular JavaScript, I would do something like:  ddl = document.getElementById("ID of element goes here"); ddl.value = 2; // 2 being the value I want to set it too.   However, I need to do this with jQuery, because I'm using a CSS class for my selector (stupid  client ids...).  Here are a few things I've tried:  $("._statusDDL").val(2); // Doesn't find 2 as a value. $("._statusDDL").children("option").val(2) // Also failed.      How can I do it with jQuery?     Update  So as it turns out, I had it right the first time with:  $("._statusDDL").val(2);   When I put an alert just above it works fine, but when I remove the alert and let it run at full speed, I get the error     Could not set the selected property. Invalid Index   I'm not sure if it's a bug with jQuery or Internet Explorer 6 (I'm guessing Internet Explorer 6), but it's terribly annoying.
119860
A weird bug was occurring in production which I was asked to look into. The issue was tracked down to a couple of variables being declared within a For loop and not being initialized on each iteration. An assumption had been made that due to the scope of their declaration they would be &quot;reset&quot; on each iteration. Could someone explain why they would not be)? (My first question, really looking forward to the responses.) The example below is obviously not the code in question but reflects the scenario:  Please excuse the code example, it looks fine in the editor preview?? for (int i =0; i&lt; 10; i++) {     decimal? testDecimal;     string testString;      switch( i % 2  )     {         case 0:         testDecimal = i / ( decimal ).32;         testString = i.ToString();             break;         default:             testDecimal = null;             testString = null;             break;     }      Console.WriteLine( &quot;Loop {0}: testDecimal={1} - testString={2}&quot;, i, testDecimal , testString ); }   EDIT: Sorry, had to rush out for child care issue. The issue was that the prod code had was that the switch statement was huge and in some &quot;case&quot;'s a check on a class' property was being made, like if (myObject.Prop != null) then testString = myObject.Stringval... At the end of the switch, (outside) a check on testString == null was being made but it was holding the value from the last iteration,hence not being null as the coder assumed with the variable being declared within the loop. Sorry if my question and example was a bit off, I got the phone call about the day care as I was banging it together. I should have mentioned I compared IL from both variables in and out the loop. So, is the common opinion that &quot;obviously the variables would not be reinitialized on each loop&quot;? A little more info, the variables WHERE being initialized on each iteration until someone got over enthusiastic with ReSharper pointing out &quot;the value is never used&quot; and removed them.  EDIT: Folks, I thank you all. As my first post I see how much clearer I should be in the future. The cause of our unexpected variable assignment can me placed on an inexperienced developer doing everything ReSharper told him and not running any unit tests after he ran a &quot;Code Cleanup&quot; on an entire solution. Looking at the history of this module in VSS I see variables Where declared outside of the loop and where initialized on each iteration. The person in question wanted his ReSharper to show &quot;all green&quot; so &quot;moved his variables closer to assignment&quot; then &quot;Removed redundant assignment&quot;! I don't think he will be doing it again...now to spend the weekend running all the unit tests he missed! How to do mark a question as answered?
42073
is there a general solution to that? I have seen simple examples for Y+X=Z but I was wondering how this would be with rescaling?
51271
As the photo - Variable 'n' has already been declared.  I've tried clearing my cache, as well as using a new user profile with no extensions, but it doesn't work.  Might be useful to know so it can be fixed before more people are using Chrome (If it's SO's fault of course!)