[opencms-dev] Firefox 3.5 Javascript Error -- Fixed, Thanks

Christian Steinert christian_steinert at web.de
Sat Jul 4 09:03:42 CEST 2009


Achim Westermann wrote:
> Hi Christian,
>
> thx for your effort. Exactly that part of tree.js has been changed, 
> checked in and works on my box now.
>  
>   
Dear Achim

thanks a lot for creating a workaround so quickly (works like a charm, 
but please also see my remark at the end).
________________

For everyone:

- the adjusted version of tree.js can be downloaded from:
http://cvs.opencms.org/viewvc.cgi/*checkout*/opencms/modules/org.opencms.workplace.explorer/resources/system/workplace/resources/commons/tree.js?revision=1.11

- This file needs to be uploaded into the following opencms folder and 
then published:
/system/workplace/resources/commons/


After that, things seem to work well with Firefox 3.5. The change is 
small and has no risk of breaking anything. The updated file does not 
only work with opencms 7.5 but also with 7.0.5.
_______________

@Achim - as an aside: (I hope that it is ok to point out the following, 
since I also did not know this very until recently and indeed really few 
people seem to do know this):
 
The comparison if( subnode != null ) does work, but it does work only 
for very peculiar reasons: This comparison checks, if foo has the 
opposite truthyness of "null". Objects are "truthy" and null is "falsy", 
so the check indirectly leads to the expected result, if subnode is 
indeed null. But values that are not declared or that were never set to 
anything, do _not_ have the value null in javascript, they have the 
value undefined. And if subnode has the value undefined then any 
comparison of subnote with something else will be false, even 
"if(subnode == null)" would be false. This means that in the end, the 
behavior of if( subnode != null ) is as one would expect, but for the 
horrible reason that various javascript specification weirdnesses cancel 
each other out and in the end lead to a false illusion of sanity where 
the language does not actually provide it. The more straightforward 
check would be to just write: if( subnode ) This will be true, if 
subnode is: a non-null object, a variable that is not undefined (as 
noted before, there is difference between undefined and null), or any 
other "truthy" value (like a non-empty string). Therefore, this check, 
will too protect against both null and undefined, but for more sane reasons.
 
A short explanation of this is available at:
http://saladwithsteve.com/2008/02/javascript-undefined-vs-null.html

Generally, it is not a good idea to do comparison against null in 
Javascript, unless one also compares against undefined. Better check a 
variable's truthyness directly in such cases, if possible.
On the other hand, if exact comparison is required (e.g. for comparing 
two strings or two numbers), then it is cleaner and much faster to use 
the not very widely used === and !== operators.

I found Douglas Crockford's videos about javascript (e.g. 
http://video.yahoo.com/watch/111593) very helpful for understanding 
these kinds of issues. Also, his jslint tool (jslint.com) is invaluable. 
He also wrote a book on Javascript a while ago, which I haven't read but 
which I would expect to be good.

Best Regards
Christian



More information about the opencms-dev mailing list