title: Event type property lost in IE-8
body: <p>I've noticed a strange Javascript error which only seems to happen on Internet Explorer 8.  Basically, on IE-8 if you have an event handler function which captures the event object in a closure, the event "type" property seems to become invalidated from within the closure.</p>
  
  <p>Here's a simple code snippet which reproduces the error:</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;script type="text/javascript"&gt;
              function handleClickEvent(ev)
              {
                  ev = (ev || window.event);
                  alert(ev.type);
                  window.setTimeout(function() {
                      alert(ev.type); // Causes error on IE-8
                  }, 20);
              }
  
              function foo()
              {
                  var query = document.getElementById("query");
                  query.onclick = handleClickEvent;
              }
  
          &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;input id="query" type="submit" /&gt;
          &lt;script type="text/javascript"&gt;
              foo();
          &lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>So basically, what happens here is that within the <code>handleClickEvent</code> function, we have the event object <code>ev</code>.  We call <code>alert(ev.type)</code> and we see the event type is "click".  So far, so good.  But then when we <em>capture</em> the event object in a closure, and then call <code>alert(ev.type)</code> again from within the closure, now all of a sudden Internet Explorer 8 errors, saying "Member not found" because of the expression <code>ev.type</code>.  It seems as though the <code>type</code> property of the event object is mysteriously gone after we capture the event object in a closure.</p>
  
  <p>I tested this code snippet on Firefox, Safari and Chrome, and none of them report an error condition.  But in IE-8, the event object seems to become somehow invalidated after it's captured in the closure.</p>
  
  <p><strong>Question</strong>: Why is this happening in IE-8, and is there any workaround?</p>