11/11/2011 08:07, Dmitry Soshnikov : > Hi, >> >> (unfortunately Twitter is again doesn't fit for a more than 140 ch >> discussion, so moving here) >> >> I'd like to still notice the possibility of accepting the "almost >> everything is expression" approach for JS. After Erlang I very often miss >> this possibility. >> >> The idea is to make most of current complex statements as expressions. >> >> Dave mentioned the proposal with `do { ... }` -- yeah, it's fine, but >> much nicer is to have "all of them" as expressions. CoffeeScript adopted >> this style as well. >> >> Besides, I'd like to note, that the thing is not just "interesting >> theoretical stuff", but really is very convenient and useful in practice. >> >> Examples: >> >> 1. Switch-expression (as addition, I eliminated `break`) >> >> let a = switch (foo) { >> case 10: 100; >> default: 200; >> }; >> >> 2. If-expression: >> >> let a = if (foo) { >> print('a is foo'); >> foo; >> } else { >> // do some longer stuff >> }; >> >
I think this is a bad idea, the difference between a block and expression is difficult enough to decide (from a sandboxing perspective). It would also make missing semi-colons continue the expression and make it really hard for the developer to track down the error and cause unintended behaviour. It adds to the complexity of deciding if a curly is a block or literal and if a "/" is a divide or regexp (which is difficult enough in JavaScript). How on earth would this be backwards compatible too? > >> We of course already have for years the expression sugar for this -- ? : >> operator, but it doesn't allow to conveniently have longer bodies of >> consequent and alternative nodes of if-expression. > > I'm pretty sure it does: 0?0:0?0:2
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss