4 ms·
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 programmi
by xg15 10y ago
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!
- bmeck 10y agotop 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.
- xg15 10y agoI wasn't aware of that restriction. That makes sense. Thanks for the info.