Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When you pass variables in JavaScript you're passing a copy of a reference to a value if it's an object, but if it's a primitive (like a true/false) you're copying the actual value. This basically means, if you pass in an object and modify one of the object's properties, you'll be modifying the original object. But if you pass in a primitive like true/false, you'll just be modifying the copy, and not the original value. So if your goal is to modify the original values, one option is to store those values in an object and pass in the object instead. For example:</p> <pre><code>var object = { pants: true, house: true, hair: {} }; function modifyObject(obj) { obj.pants = true; obj.house = true; obj.hair = true; } </code></pre> <p>If you want to modify an arbitrary number of arguments, just remember that if you're passing in true/false you're copying those values. So if you change them inside the function you won't be modifying the original values.</p> <p>A quick way to remember this is if you ever pass an object or an array, you're modifying the actual object. Anything else, you're modifying a copy.</p> <p>Edit</p> <p>So interpreting what you want to do literally, you could write this:</p> <pre><code>var a = true, b = true; /* pass in variable names */ function makeFalse() { var i, len; for (i = 0, len = arguments.length; i &lt; len; ++i) { window[arguments[i]] = false; } } makeFalse("a", "b"); </code></pre> <p>But I can't think of a good reason to do this :-). I would use configuration objects to store flags and state variables, not global variables.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload