Hacker News new | past | comments | ask | show | jobs | submit login

Here it is with line breaks and as many extra legal parens as I can add without redundancy, showing all the unary and binary operators involved:

  return (
    yield (
      delete (
        void (
          await (
            (null) in (
              (this) instanceof (
                typeof (
                  new (
                    class extends (
                      async function () {}
                    ) {}
                  )()
                )
              )
            )
          )
        )
      )
    )
  )
`class extends X {}` is an anonymous class extending X. Syntactically, X is an arbitrary expression, which `async function () {}` is. At runtime, X must be a constructor on pain of TypeError, and an async function isn’t; this could be considered grounds for disqualification, as under no circumstances will it execute without exceptions.

`new` does not require an identifier or path to follow it: it can be an expression. So `new (foo)` is fine. It’s just kinda greedy as regards an open paren of a function call: `new foo.bar(baz)(quux)` is equivalent to `(new (foo.bar)(baz))(quux)` rather than any alternative grouping. Remember also that `new foo` is legal, and equivalent to `new foo()`.




TIL class expressions and anonymous classes are a thing that exists in JavaScript.


It’s the same thing as function expressions and anonymous functions, but with classes instead of functions.




Applications are open for YC Summer 2021

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: