1816RE: [jslint] Re: Bad variable names
- Jan 25, 2011I grant that technically a global and local variable of the same name are
completely different, but I'd propose that it's very confusing to those
unfamiliar with the codebase when local variables are named identically to
global variables. If for no other reason than other programmers might get
confused, it seems better to error on the side of caution, prohibiting the
declaration of identically named local variables to globally defined
variables elsewhere in the file or variables defined in /*global */ or
global variables triggered by other options such as "browser". If nothing
else, I see value in the ability to opt into a warning when such an event
has occurred -- like the current list of global variables in the report.
From: email@example.com [mailto:firstname.lastname@example.org] On
Behalf Of Douglas Crockford
Sent: Tuesday, January 25, 2011 2:32 PM
Subject: [jslint] Re: Bad variable names
--- In email@example.com, "Ezequiel" <thehungerforce@...> wrote:
> Well, JSLint already has this.
> var String = '';
> => Problem at line 1 character 5: Redefinition of 'String'.
> JSLint doesn't see this as an issue if we do it inside a function,
> Whether you initialize that var inside or outside a function, it still has
the same effect of redefining "String."
That's not true at all. var String inside of a function declares a local
variable that can only be seen by the code you put into that function with
it. That is nothing like redefining a primordial global variable.
- << Previous post in topic Next post in topic >>