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

Re: The Comma Operator Causes JSLint to Stop Prematurely

Expand Messages
  • urangatang@att.net
    Also, I noticed that JSLint does not throw any warning at all for the Comma Operator in the MDC example: for (var i=0, j=9; i
    Message 1 of 6 , Jul 20, 2010
    • 0 Attachment
      Also, I noticed that JSLint does not throw any warning at all for the Comma Operator in the MDC example:

      for (var i=0, j=9; i <= 9; i++, j--)
      document.writeln("a["+i+"]["+j+"]= " + a[i][j]);

      Is that a mistake, or is this an acceptable use of commas?



      --- In jslint_com@yahoogroups.com, "urangatang@..." <urangatang@...> wrote:
      >
      > I'm trying to clean up some code with JSLint, but I have been running
      > into a problem with JSLint stopping prematurely when it comes across the
      > Comma Operator
      > <https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Operator\s/Special_Operators/Comma_Operator> .
      > Here is a simple example:
    • Cheney, Edward A SSG RES USAR USARC
      That is perfectly valid and acceptable. for (var i=0, j=9; i
      Message 2 of 6 , Jul 21, 2010
      • 0 Attachment
        That is perfectly valid and acceptable.

        for (var i=0, j=9; i <= 9; i++, j--)
        document.writeln("a["+i+"]["+j+"]= " + a[i][j]);

        It is a standard for loop with the required three semicolon separated sections. The first section is a single var command applied to a list of variables. The third section defines how an iteration of the loop is manifest. In this case the loop cause the "i" variable to increment by one and the "j" variable to simultaneously decrement by one.

        From a stylistic perspective this type of looping is risky if closures are contained in this loop. The loop is logically solid and straight forward because all that matter is the value of "i" for termination. I say this loop is risky because the loop changes the value of two variables simultaneously and independently. Any automated changes that occur simultaneously at absolute independence from each other always result in higher levels of complexity for debugging while possibly allowing a hidden conveyance for errors between separate pieces of consuming logic.

        Austin Cheney
        http://prettydiff.com/
      Your message has been successfully submitted and would be delivered to recipients shortly.