kjs: about if(undefvar)...

Harri Porten porten at kde.org
Sat Jan 11 15:28:35 GMT 2003


On Sat, 11 Jan 2003, Koos Vriezen wrote:

>       eval("if (xxx) alert('defined'); else alert('undefined');");

> has changed. It now throws an exception (used to be 'false' iirc). Is that
> correct behaviour?

Yes. The behaviour is correct as I see it. It's a consequence of fixing
the Windows object after David and me believe to finally understand why

  if (xxx)
     var xxx = 0;

works. The difference to your case: the variable *is* declared. Order of
declaration doesn't matter.

> (I need to change the js code in netscape.javascript.JSObject if so) > 

How about the following check:
  
  if (window.xxx) {
     ....
  }

The direct check can be made without risking an exception.

Harri.





More information about the kfm-devel mailing list