I noticed a strange Javascript error that seems to be happening in Internet Explorer 8. Basically, on IE-8, if you have an event handler function that captures an event object in closure, an event property of the type "seems" to become invalid from -for closing.
Here is a simple piece of code that reproduces the error:
<html> <head> <script type="text/javascript"> function handleClickEvent(ev) { ev = (ev || window.event); alert(ev.type); window.setTimeout(function() { alert(ev.type); </script> </head> <body> <input id="query" type="submit" /> <script type="text/javascript"> foo(); </script> </body> </html>
So basically what happens here in the handleClickEvent function is an ev event object. We call alert(ev.type) , and we see that the type of the event is "click". So far, so good. But then, when we capture the event object in the closure, and then call alert(ev.type) again from within the closure, Internet Explorer 8 errors now suddenly appear, saying "Member not found" due to the expression ev.type . It seems that the type property of the event object mysteriously disappeared after we committed the event object to close.
I tested this piece of code on Firefox, Safari, and Chrome, and none of them reported an error. But in IE-8, the event object seems somehow invalid after it is captured in closure.
Question : Why is this happening in IE-8, and is there a workaround?
source share