Re: JSLint and JavaScript: The Good Parts.



On 03/12/2010 07:04 AM, Lex Hider wrote:
> I ran the attached perl script to get around errors reported for: let,
> const, and multiple variable assignment (e.g. [a,b] = callFunc();),
> which appear to be mozilla specific features.

yeah, there's a bug in bugzilla (against gjs) about trying to get jslint
working with the moz extensions

> Would a patch for any of the following be worthwhile?
> 
> * missing terminal semi-colons.

yes

> * if statement's with single statement but no braces.

no, our style allows that (although if there are places where one branch
has braces and the other doesn't, you can fix that).

> * unused variables.

yes

> * changing use of == and != to === and !== .
> if (foo != null) // should be: if (foo !== null)
> Crockford is strong on this, referring to == and != as the evil twins to
> ===/!== .

Changing them blindly would break some things. (Eg, I know there are
places where people have taken advantage of the fact that 0 != null but
undefined == null; changing != to !== would make both 0 and undefined
compare as not equal.) You could argue that doing that is bad style and
should be written differently. But at any rate, this isn't something you
can change without examining the code carefully.

> //changing this
> if (fee && fi
>     && foe && fum)
> //to
> if (fee && fi &&
>     foe && fum)

So, I prefer the latter style anyway, but this is a bad example since it
wouldn't be valid for the interpreter to put a semicolon in there anyway...

-- Dan


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]