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

Re: return [expression] -> "unable to continue"

Expand Messages
  • Douglas Crockford
    ... I think by fail you meant that it succeeded in finding the weakness in your code. ... This is explained in the documentation. When = is used in an
    Message 1 of 3 , Oct 30, 2008
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, "crlender" <crlender@...> wrote:
      >
      > The following example causes the JSLint parser to fail:

      I think by "fail" you meant that it succeeded in finding the weakness
      in your code.

      > return cache = calculate();

      > Using extra parentheses works:
      >
      > return (cache = calculate());
      >
      > Since parens are not required here (ECMA-262, ed3, 12.9), and JSLint
      > normally complains about extra parens, I wanted to ask if that's on
      > purpose or a bug?

      This is explained in the documentation. When = is used in an
      expression, there is a high likelihood that it is an error caused by
      mistyping == or ===. From a careful reading of your code, I can't be
      sure if your code is in error or not. That is not good. You want your
      code to be more clearly correct. By wrapping the assignment in parens,
      you are demonstrating that you are doing this deliberately.

      I recommend avoiding assignment in expressions. I think

      cache = calculate();
      return cache;

      is cleaner and more bug resistant.
    • crlender
      ... No, I meant fail as in couldn t continue parsing the source . If it finds a weakness, it should issue a warning and move on. ... Ah, now I see where
      Message 2 of 3 , Oct 30, 2008
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...>
        wrote:
        > > The following example causes the JSLint parser to fail:
        >
        > I think by "fail" you meant that it succeeded in finding the weakness
        > in your code.

        No, I meant "fail" as in "couldn't continue parsing the source".
        If it finds a weakness, it should issue a warning and move on.

        > This is explained in the documentation. When = is used in an
        > expression, there is a high likelihood that it is an error caused by
        > mistyping == or ===.

        Ah, now I see where this is coming from, and you've got a point. I
        always use extra parens when an assignment could be misunderstood
        as a test. Thanks for the explanation.


        - Conrad
      Your message has been successfully submitted and would be delivered to recipients shortly.