On Wed, Mar 21, 2018 at 11:02 AM, Rodrigo <[email protected]> wrote:

> My proposal is to keep it simple and implement the if-assignment `if(
> const o = ...; ! o ) { ... }` mimicking the `for(;;)` assignment
> behavior.
>

Fair enough.  If the assignment is separate from the condition, then none
of that matters.
That question only pertained to let/const declarations used for their value.

That way we can scope a variable to the `if` block and we can do that
> *separately* from assignment.
>
> Assigning and comparing at the same time opens up all sort of oddities
> as the variable transitions from lvalue to comparison operand. This
> already exists in the language and is definitely not good practice.
>
> `if.value`, as proposed earlier is a bombshell similar to `this`,
> which could easily get scrambled with the introduction of additional
> `if` blocks.
>
> The beauty of `if(;)` is that it makes scope blocks possible while
> avoiding the asymmetric behavior caused by assigning and comparing in
> one go.
>
>         if( let people=getTeamArray(); people.length > 2 ) {
>            console.log("it's a crowd", people.join(','));
>        }
>        else if( people.length == 2 ) {
>            console.log("just a pair");
>        }
>        else if( people.length == 1 {
>            console.log("solo");
>        }
>        else {
>            console.log("none");
>        }
>

IIUC, it sounds like the right side could be syntactic sugar for the left
side.
If that's right, what about the left side warrants new syntax to enable the
right?


CurrentProposed

  {
       *let people = getTeamArray();*
       if( people.length > 2 ) {
           console.log("it's a crowd", people.join(','));
       }
       else if( people.length == 2 ) {
           console.log("just a pair");
       }
       else if( people.length == 1 {
           console.log("solo");
       }
       else {
           console.log("none");
       }
  }

   if( *let people = getTeamArray();* people.length > 2 ) {
       console.log("it's a crowd", people.join(','));
   }
   else if( people.length == 2 ) {
       console.log("just a pair");
   }
   else if( people.length == 1 {
       console.log("solo");
   }
   else {
       console.log("none");
   }


I can imagine that it might be nice when used later in an else-if chain:

if (c0) {
  ...
} else (let x = v1, c1(x)) {
  ...
} else ...

vs

if (c0) {
  ...
} else {
  let x = v1;
  if (c1(x)) {
    ...
  } else ...
}

Can you point at any particularly tricky code that could be simplified by
this?
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to