Legitimate uses of IIFEs?

Bergi a.d.bergi at web.de
Sun Dec 20 21:39:11 UTC 2015


Andrea Giammarchi schrieb:

> Reading this thread felt like one problem is gone and another is coming ...
> and to be honest, a `module.exports = new Promise(myModule);` should most
> likely become a new standard for asynchronously defined modules in the
> node.js world, and I've no idea how that could be represented through the
> current ES2015 specs which seem to assume every module loading could be
> asynchronous, but the exported behavior would  be definitively sync.

I think a top-level (read: module-level) `await` could solve this quite 
elegantly.

> ... or maybe I am missing something, like the fact if a module export a
> Promise it's automatically usable no matter if the requester was within a
> sync execution or async?

That would be up to the loader. But I don't think a module loader should 
mess with these things, for various reasons. Error (=rejection) handling 
would be obscure. Sometimes I *want* to export promises without anyone 
awaiting them. And of course, exports do resolve to variable bindings, 
not to values, so this would be hard to align with the current spec.

Regards,
  Bergi


More information about the es-discuss mailing list