> Is it possible to extend JavaScript syntax to support Swift style block 
> syntax[1]?
> 
> In Swift it's possible to omit return keyword 
> ```
> reversed = names.sort( { s1, s2 in s1 > s2 } )
> ```

As you note below this is already possible in es6, and might I add, has much 
more intuitive syntax in Es6. The swift syntax looks like a list comprehension 
gone wrong.

> or omit argument declaration like this:
> 
> ```
> reversed = names.sort( { $0 > $1 } )
> ```

I for one think this is a bad idea - use rest arguments instead. It's pretty 
terrible as far as readability goes, although I'd like to see more examples of 
it being used in Swift code.

> or apply an operator to arguments of a function 
> 
> ```
> reversed = names.sort(>)
> ```

This might actually be possible - I can't think of any ambiguous situations for 
passing operators as if they were first class functions. If it is possible, I'd 
like to see this done.

> 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]
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to