Style - replacing the name of the function with the name IIFE

I am refactoring code. Is it possible to replace

function next () { // call next using setTimeout } next(); 

with

 (function next () { // call next using setTimeout }()); 

next must be initiated, and from there it will call itself a certain number of times.

+4
source share
1 answer

Both options are possible, both allow a recursive call (which is the point in the IIFE naming convention).

The only difference between the two is that the second does not pollute the external namespace with the function name, which is visible only from the function. Of course, the consequence is that you cannot call the function from another place.

+9
source

All Articles