noizZze

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!