Conditional function definitions in IE5

It looks like all cool kids except for IE5 know what to do with this:

if (some_condition) {
  function f() { alert(”true”); }
} else {
  function f() { alert(”false”); }
}

When calling f(), Firefox and Safari will show “true” when some_condition was TRUE at the load time, and “false” when it evaluated to FALSE. IE5 pays attention to the if-else construction (and no code will be executed in the else-block if the some_condition is FALSE), but it DOES redefine the function. Yes, even though it’s in that block that’s not being executed.

Be careful!

3 Responses to “Conditional function definitions in IE5”

  1. Andrew Dashin Says:

    IE5? Does anybody still use it? :)

    Look here - http://webbugtrack.blogspot.com/ probably you’ll find a lot of interesting things and all around browsers :)

  2. Aleksey Gureiev Says:

    Believe it or not. :)

  3. Aleksey Gureiev Says:

    Amazing bug parade btw!

Leave a Reply