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

722Re: [jslint] Nested ?: operator values.

Expand Messages
  • pauanyu
    Jul 8 9:09 PM
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, Michael Lorton <mlorton@...> wrote:
      >
      > Well, val1 and val2 are the only possible values, you could do this:
      >
      > var next = {};
      > next[val1]=val2;
      > next[val2]=val1;
      > return this[prop] = next[this[prop]] ;
      >
      > If the function is to be executed over and over, the first three statement are only needed at initialization time. Plus, this algorithm generalizes to any fixed, repeating sequence of values. Say you wanted to loop through 1, 4, 9 over and over (starting at 1 if the property is not already in the sequence):
      >
      > return this[prop] = { 1: 4, 4: 9, 9: 1} [this[prop]] || 1;
      >
      > Was this the question or did you want to talk about the ternary operator?
      >
      > M.
      >

      That seems to be a good solution as well. However, that was not the question. I was indeed talking about the ?: operator, specifically about a JSLint error when nesting them. I appreciate the alternate solution, however.
    • Show all 7 messages in this topic