Loading ...
Sorry, an error occurred while loading the content.

1816RE: [jslint] Re: Bad variable names

Expand Messages
  • Rob Richardson
    Jan 25, 2011
    • 0 Attachment
      I 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.


      -----Original Message-----
      From: jslint_com@yahoogroups.com [mailto:jslint_com@yahoogroups.com] On
      Behalf Of Douglas Crockford
      Sent: Tuesday, January 25, 2011 2:32 PM
      To: jslint_com@yahoogroups.com
      Subject: [jslint] Re: Bad variable names

      --- In jslint_com@yahoogroups.com, "Ezequiel" <thehungerforce@...> wrote:
      > Well, JSLint already has this.
      > ie.
      > 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.
    • Show all 9 messages in this topic