logoalt Hacker News

nadinenglandlast Friday at 1:30 PM4 repliesview on HN

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 = ...

  ...

  return compiled;
})()'

const result = config.whatever;

// carry on

return result; ```

Really wish block were expressions in more languages.


Replies

dwatttttyesterday at 12:22 AM

By the by, code blocks on here are denoted by two leading spaces on each line

  like
  this
notpushkinyesterday at 6:48 AM

Interesting that you can use blocks in JS:

  {
    const x = 5;
    x + 5
  }
  // => 10
  x
  // => undefined
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.
charleszwlast Friday at 10:57 PM

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?)

show 1 reply
pwdisswordfishyyesterday at 10:17 AM

https://github.com/tc39/proposal-do-expressions

(Not to be confused with do notation)