Email conversation
From | Jörn Zaefferer |
To | Me |
Subject | Why Firefox's strict JavaScript warnings are useful |
Date | 15 November 2006 14:02 |
Hi Mark!
Just today I was looking for a way to force Firefox to tell me about
problems that is does otherwise ignore, but cause problems in other
browsers (ie. IE). A good example for this are trailing commas in object
initializers, which are not allowed, but ignored by Firefox.
So I searched for "firefox javascript strict" and came across your article
"Why Firefox's strict JavaScript warnings are wrong". While it lacks
useful details about actually enabling the strict mode, it was otherwise
quite interesting.
After testing the strict mode for myself I found it very useful, as it
warns me about the problems that may occur in IE.
So I read on to understand why you think it is bad. Maybe I'm missing
something, but I'd rewrite your examples to include an additional check
that removes any warnings:
if( document.body.childNodes[10] == e.target ) {
becomes
if( document.body.childNodes[10] && document.body.childNodes[10] ==
e.target ) {
if( document.onclick == myFunction ) {
becomes
if( document.onclick && document.onclick == myFunction ) {
Adding the additonal check removes the warning. Therefore the strict mode
promotes good coding style, by checking for the existance of properties
first before accessing them.
Please consider adding this to your article.
Regards
Jörn
From | Me |
To | Jörn Zaefferer |
Subject | Re: Why Firefox's strict JavaScript warnings are useful |
Date | 15 November 2006 16:34 |
Jörn,
> if( document.body.childNodes[10] == e.target ) {
> becomes
> if( document.body.childNodes[10] && document.body.childNodes[10] == e.target ) {
You missed the point totally, and yes, you are yet another person who has
been confused by those stupid warnings. This extra check is totally
pointless and needless in JavaScript. The language is not strictly typed, it
can check any value against any other value without them needing to be the
same type. All you are doing is wasting CPU cycles.
> Adding the additonal check removes the warning. Therefore the strict mode
> promotes good coding style, by checking for the existance of properties
> first before accessing them.
That is not good coding in JavaScript. It may work, sure, but it is
inefficient wasteful programming in a language that is already slow enough
(being interpreted). Your suggestion runs approximately 200% slower in IE,
Firefox and Opera, according to my tests. I do not consider that useful at
all.
Firefox has conned you into thinking it is wrong to do what I did, which it
is not. This is why I say, and firmly maintain, those warnings are wrong.
Please see this conversation for more:
http://www.howtocreate.co.uk/emails/DougWright.html
Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/