Hacker News new | ask | show | jobs
by asherah 1121 days ago
i'd say that it's a bit more readable:

  run(() => { return foo })
looks better than, and assuming pre-existing knowledge of what `run` does, is more understandable than

  (() => { return foo })()
but this is also a fairly contrived example
1 comments

I agree that `run()` is more readable than an IIFE if you remove all context and history from the analysis. But the IIFE is a well-known idiom to JavaScript programmers, so readers will not have to pay a cognitive "what is `run()` do?" penalty in order to understand the code.

New abstractions have a cost, and "clever" abstractions tend to confuse the average developer more than the benefit they provide.

If there's a problem with an IIFE (yes, they can be abused), the usual approach is to replace it with a named function definition. This works in their React example as well--rather than (necessarily) creating a new component as they suggest, the standard approach is to add a named rendering helper in the function closure that returns JSX.