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

Re: Nested loops with the same control vars

Expand Messages
  • Chris
    I agree: I think such a rule would be a useful improvement to JSLint. I have seen this sort of situation causing numerous bugs in my own code. Of course, we
    Message 1 of 5 , May 10, 2012
    • 0 Attachment
      I agree: I think such a rule would be a useful improvement to JSLint. I have seen this sort of situation causing numerous bugs in my own code. Of course, we have discussed this before:

      http://tech.groups.yahoo.com/group/jslint_com/message/2212

      Also, some time later, I found a bug in JSLint itself that was caused by this coding practice:
      http://tech.groups.yahoo.com/group/jslint_com/message/2372

      When you have nested scopes, the idea of declaring variables in an outer scope and redeclaring them in an inner scope is naturally confusing. I argue that any code written in this way could be written more clearly by giving the variables distinct names.

      - Chris

      --- In jslint_com@yahoogroups.com, "Rob Richardson" <erobrich@...> wrote:
      >
      > I think an even larger issue should be checking for identically named
      > variables declared in different scope. This too should be illegal:
      >
      > function a() {
      > ````var i;
      > ````function b() {
      > ````````var i;
      > ````};
      > };
    Your message has been successfully submitted and would be delivered to recipients shortly.