| ▲ | nadinengland 3 days ago | |||||||
I love that this is part of the syntax. I typically use closures to do this in other languages, but the syntax is always so cumbersome. You get the "dog balls" that Douglas Crockford always called them: ``` const config = (() => { const raw_data = ...
})()'const result = config.whatever; // carry on return result; ``` Really wish block were expressions in more languages. | ||||||||
| ▲ | dwattttt 2 days ago | parent | next [-] | |||||||
By the by, code blocks on here are denoted by two leading spaces on each line | ||||||||
| ▲ | notpushkin 2 days ago | parent | prev | next [-] | |||||||
Interesting that you can use blocks in JS:
But I don’t see a way to get the result out of it. As soon as you try to use it in an expression, it will treat it as an object and fail to parse. | ||||||||
| ▲ | charleszw 3 days ago | parent | prev | next [-] | |||||||
Yes, I constantly use this pattern in C++/JavaScript, although I haven't tested how performant it is in the former (what does the compiler even do with such an expression?) | ||||||||
| ||||||||
| ▲ | pwdisswordfishy 2 days ago | parent | prev [-] | |||||||
https://github.com/tc39/proposal-do-expressions (Not to be confused with do notation) | ||||||||