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

Assignment in if statement + Move the invocation into the parens...

Expand Messages
  • m_blasz
    I have 2 questions. 1. Is there a JSLint option to tolerate variable assignments in if statements? If so, which one? 2. Why should we Move the invocation into
    Message 1 of 2 , Oct 8, 2011
    View Source
    • 0 Attachment
      I have 2 questions.

      1. Is there a JSLint option to tolerate variable assignments in if statements? If so, which one?

      2. Why should we 'Move the invocation into the parens that contain the function'? I didn't see the reason in http://www.jslint.com/lint.html or http://javascript.crockford.com/code.html

      Cheers.
    • Merlin
      ... No. There are ways around it, if you really must: var a, b; if (a === b) { a = 1; } // OK if (a = b) { a = 1; } // NOT OK if (!!(a = b)) { a = 1; } // OK
      Message 2 of 2 , Oct 8, 2011
      View Source
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "m_blasz" <blasz_2000@...> wrote:
        >
        > I have 2 questions.
        >
        > 1. Is there a JSLint option to tolerate variable assignments in if statements? If so, which one?
        >

        No.

        There are ways around it, if you really must:

        var a, b;
        if (a === b) { a = 1; } // OK
        if (a = b) { a = 1; } // NOT OK
        if (!!(a = b)) { a = 1; } // OK

        > 2. Why should we 'Move the invocation into the parens that contain the function'?

        FRED = (function() { .... }());

        looks clearer than

        FRED = (function() { .... })();
      Your message has been successfully submitted and would be delivered to recipients shortly.