title: Safe use of "with" in JavaScript
body: <p>Pretty much every resource documenting <code>with</code> that I can find warns against using it, mostly because if a variable is not defined it may have unpredictable effects.</p>
  
  <p>I want to understand it so that I can make effective use of it - after all, it's there for a reason. Even <code>eval</code> has its non-evil uses!</p>
  
  <p>So, with that in mind, let's say I want to delete all child nodes from an element, without using <code>elem.innerHTML = "";</code></p>
  
  <p>Would the following be safe?</p>
  
  <pre><code>with(elem) while(firstChild) removeChild(firstChild);
  </code></pre>
  
  <p>Note that at this point I'm not caring for readability, just functionality. Since <code>firstChild</code> is a property of, and <code>removeChild</code> a method of, all element nodes, it should be fine to use <code>with</code> this way, right?</p>
  
  <p>Similarly, let's say I want to set some styles.</p>
  
  <pre><code>with(elem.style) {
      color = "red";
      backgroundColor = "black";
      fontWeight = "bold";
  }
  </code></pre>
  
  <p>Since all of these are properties of the style object (even if not defined in the stylesheet, they are there as empty strings), it's fine to use <code>with</code> like this, right?</p>
  
  <p>Am I missing something, or is the constant warning to not use <code>with</code> similar to the one against PHP's <code>mysql</code> extension: a protection against dumb programmers?</p>