Swift style syntax

Mohsen Azimi me at azimi.me
Sun Oct 11 15:45:36 UTC 2015


Is it possible to extend JavaScript syntax to support Swift style block
syntax[1]?

In Swift it's possible to omit return keyword
```

   1. reversed = names.sort( { s1, s2 in s1 > s2 } )

```

or omit argument declaration like this:

```

   1. reversed = names.sort( { $0 > $1 } )

```

or apply an operator to arguments of a function

```

   1. reversed = names.sort(>)

```
We have the first feature in ES2015 already:

```
let sorted = names.sort((a, b)=> a > b);
```

But for omitting argument declaration we need to find an alternative to $0,
$1... since those are valid variable names in JS. Maybe we can use #0,
#1... instead.

This is very useful for functional programming aspect of JS. For example in
a filter function:

```
let passed = objs.filter(#0.passed)
```




[1][
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Closures.html
]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20151011/2115493b/attachment.html>


More information about the es-discuss mailing list