Legitimate uses of IIFEs?

Fabrício Matté ultcombo at gmail.com
Sun Dec 20 22:07:50 UTC 2015


On Sun, Dec 20, 2015 at 7:32 PM, <bread at mailed.me.uk> wrote:

> there is no reason to create an async function to invoke another async
> function; one can simply invoke it, and if the result/completion is
> required, use it's ,then() member....but there's no need/advantage to
> wrapping such an invocation in an IIAFE, right?


I believe the advantage is that you can then replace the
`.then(onFulfilled, onRejected)` constructs with `await/try/catch`, thus
simplifying the code and improving readability. I recognize this may be an
uncommon pattern though, as most often the caller of an async function will
be an async function as well. Note that I say "uncommon" referring to async
IIFEs inside non-async functions; async IIFEs are still very useful to
parallelize sequences of async operations as I've mentioned before.

Btw, the term "IIAFE" should probably be avoided, as the "A" can
ambiguously mean "Arrow" or "Async".

/fm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20151220/13b873e8/attachment.html>


More information about the es-discuss mailing list