4

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.

4

1 回答 1

9

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.

于 2013-03-30T17:31:15.057 回答