News for hackers. Stuff that matters.
Re:Top-level await in JavaScript is a footgun by xg15 on Wednesday September 14, 2016 @01:14PM (#12499125)
Slighty off-topic, I'm surprised/amazed that top-level await is permitted at all.

This looks like it would allow some interesting new patterns in web programming, though at the expense of wreaking havoc with traditional execution models.

For example, await in event handlers:

  <button onclick="await doOneThing(); doAnotherThing()">
Is the event object still valid when doAnotherThing is called?

Or await in script blocks:

  <p>Welcome back,
    <script>
     document.write(await fetchUsername());
    </script>
  </p>
Look ma, I stalled the page load with no synchronous XHR!
Re:Top-level await in JavaScript is a footgun by bmeck on Wednesday September 14, 2016 @01:24PM (#12499225)
top level await is only possible in grammar w/ `await` as a reserved word. This is limited to Modules (type=module) and async functions. You can't put it in your click handler or random Script like the examples you gave.
Re:Top-level await in JavaScript is a footgun by xg15 on Wednesday September 14, 2016 @04:21PM (#12500907)
I wasn't aware of that restriction. That makes sense. Thanks for the info.