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

Order of Evaluation (OT?)

Expand Messages
  • mbrrtt
    This may be slightly offtopic, but since the question relates to proper style and there are many JS experts in this group, I m posing the question here. Can
    Message 1 of 4 , Jun 22, 2009
    • 0 Attachment
      This may be slightly offtopic, but since the question relates to
      proper style and there are many JS experts in this group, I'm posing
      the question here.

      Can you rely on the order of evaluation of comma-separated
      initializing assignments in a 'var' statement? That is, can you rely
      on the order of evaluation being the same as the order in which the
      assignments are written? I can't find a clear answer in the ES-262
      spec, and it becomes germane because JSLint recommends a single 'var'
      statement per function.

      I'd like to write something like:

      var ...,
      defaultEpsilon = 1.0E-7,
      epsilon = defaultEpsilon,
      ... ;

      But since that would not work if the assignments were reversed and
      I'm not sure about the order of evaluation, I've been writing:

      var ...,
      defaultEpsilon = 1.0E-7,
      epsilon,
      ... ;
      epsilon = defaultEpsilon;


      Does anyone know if I can count on the first version being ok, and if
      so, will that remain true for ES5?
    • mbrrtt
      And does anyone know how to write code and (especially) how to get proper indentation in posts to this group?
      Message 2 of 4 , Jun 22, 2009
      • 0 Attachment
        And does anyone know how to write code and (especially) how to get proper indentation in posts to this group?
      • christian.wirkus
        var x = 1, y = 2 * x, z = x + y; x === 1; y === 2; z === 3; You can rely on the evaluation to be from left to right or top to bottom. How to indent? I don t
        Message 3 of 4 , Jun 23, 2009
        • 0 Attachment
          var x = 1, y = 2 * x, z = x + y;

          x === 1;
          y === 2;
          z === 3;

          You can rely on the evaluation to be from left to right or top to bottom.
          How to indent? I don't know.



          --- In jslint_com@yahoogroups.com, "mbrrtt" <mbrrtt@...> wrote:
          >
          > And does anyone know how to write code and (especially) how to get proper indentation in posts to this group?
          >
        • pauanyu
          ... As to your first question... In my experience, yes. It s treated as if you had used two separate vars, so the order is maintained. No clue if it ll stay
          Message 4 of 4 , Jun 23, 2009
          • 0 Attachment
            --- In jslint_com@yahoogroups.com, "mbrrtt" <mbrrtt@...> wrote:
            >
            > And does anyone know how to write code and (especially) how to get proper indentation in posts to this group?
            >

            As to your first question... In my experience, yes. It's treated as if you had used two separate vars, so the order is maintained. No clue if it'll stay the same in ECMAScript 5, but I would imagine so.

            As to your second question... I believe you can't. However, those who are reading your post can click the little "Show Message Option" link on the right side, then hit "Use Fixed Width Font". This causes indentation to show up properly. It's only for those reading your post, not something you toggle while posting.
          Your message has been successfully submitted and would be delivered to recipients shortly.