3 ms·
Why Firefox's strict JavaScript warnings are wrong
- viraptor 17y agoI think this guy got it all wrong. He complains that strict mode warns on `if(document.body.childNodes[10] == e.target)` if it can't resolve `childNodes[10]` for example. But it should! One can check the number of elements before trying to get the 10'th one. Same with other comparisons: he wants to do `e.xxx == this`, but strict mode warns, because it might not exist. Well - that's what `if (e.xxx)` is for. He mentions the only thing that might be useful is not implemented - warning when using a variable from a parent scope... except doing that is perfectly normal and valid. His whole argument seems to be a complete mistake.
- DanHulton 17y agoWhile not wrong, the author comes off as a self-important dick and I want to prove him wrong because of it. If he's wrong just once, he'll never live it down because of his attitude.
- swolchok 17y agoBut it does warn you if you do not use the var keyword the first time you assign a value to a variable. In JavaScript that is not really necessary since it will automatically create a variable in the global scope anyway. Still it doesn't hurt to do things properly and declare the variable using the var keyword. But since the only time you are really interested in that sort of error is when you overwrite the variable from the parent scope, it becomes useless for the one thing it could have been useful for. What about, y'know, enforcing the non-use of globals?