Style - Replacing named function with named IIFE

javascript

Solution

Both are possible, both enable recursive call (that's the point in naming the IIFE).

The only difference between them is that the second one doesn't pollute the external namespace with the function's name, which is only visible from the function. Of course a consequence is that you won't be able to call the function from elsewhere.

Problem

I'm refactoring some code. Can I replace ``` function next () { // call next using setTimeout } next(); ``` with ``` (function next () { // call next using setTimeout }()); ``` next has to be initiated and from there it will call itself a certain amount of times.

Original source

Related problems