Is this part of the standard?
It's a Stage 3 proposal https://github.com/tc39/proposal-top-level-await
11–20 of 310 posts
Is this part of the standard?
It's a Stage 3 proposal https://github.com/tc39/proposal-top-level-await
This is huge! Finally no more need to use IIFE's for top level awaits
It not only works for the main entrypoint module, but all other modules as well.
Though I can say I've ever encountered a reason to have that....
Is this part of the standard?
In other words, it's all but standardized. Barring significant blockers coming from actual implementation experience this will most likely be ratified.
Earlier quoted context omitted.
What is an IIFE?
Immediately invoked function expression - aka an anonymous function that executes as it is interpreted. (function() { console.log('test'); })(); In old versions of JavaScript, variables had to be scoped to the nearest function (rather than the nearest block) so IIFE where often used for namespacing: var $ = (function() { this.version = '1.2.3'; })(); $.version; // 1.2.3 This worked because the function would be immed…
A proper example of IIFE for lexical scoping would be something like this:
var numbers = "";
(function(){
for (var i=0; i
Nowadays of course you could just use let instead of varYour code snippet would kind of work as expected if used as a constructor. As in:
var $ = function() { this.version = '1.2.3'; };
var obj = new $;
console.log(obj.version); //1.2.3
Of course that is not a IIFE.Ah...brings me back to my SO days...
This is huge! Finally no more need to use IIFE's for top level awaits
It's nice, I guess, but huge? Instead of: async function main() { // code } main().catch(console.error); I'll be maybe writing: try { // code } catch (ex) { console.error(ex); } Hrm?
There is also the original use case that the original proposal of needing to do async calls when during module loading.
It doesn't matter that it's all single threaded if all your function calls may or may not block and run a bunch of other code in the meantime, mutating all kinds of state.
I feel like JavaScript developers of the 2020's are going to relearn the same things the C programmers of the 1990's learn, just a few levels of abstraction higher.
Is this part of the standard?
Did you read the commit? The spec material was linked: https://tc39.es/proposal-top-level-await/#sec-execute-async-... It's a Stage 3 proposal https://github.com/tc39/proposal-top-level-await
Welcome to the internet!