Proposal: expression mode (=)

Yongxu Ren renyongxu at gmail.com
Sun Oct 30 00:20:55 UTC 2016


This proposal makes it easier to write functional code, you can convert
statements block into expressions producing a useful result and plugging
that back into an expression context.

This proposal is an alternative to the 'do expressions'.


Prepending `=` will automatically convert `if...else`, `switch...`, `block`
into statement that returns last inner statements value by default.

examples:

```

// the following 3 lines are equivalent

console.log(=if (expr) {a} else {b})

console.log(=if (expr) a else b)

console.log(expr ? a : b)

// print the value of statement3

console.log(={

  statement1

  statement2

  statement3

})

```


If the left hand side is an expression or operator, '=' can be omitted

```

LeftHandSideExpression = if (condition)

   statement1

[else

   statement2]

let someVal = LeftHandSideExpression * if (condition)

   statement1

[else

   statement2]

```

examples:

```

// the following 3 examples are equivalent

let x = if (expr) {a} else {b}

let x = if (expr) a else b

let x = expr ? a : b


let x = {

// statements here

console.log('print unicorn')

y // will assign y to x

}

```
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20161029/e54d83f2/attachment.html>


More information about the es-discuss mailing list