Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

Both good questions.

The immediately invoked function is really just a slightly less verbose way to do this:

    function resolver() {

    }

    return resolver();
The reason that I gave it a name instead of using an anonymous function (as is common with immediately invoked function expressions) is because I need to be able to call it from within itself. This function is all about creating a closure where we can store all of the arguments we've received so far.

As for your second point: The first time that `resolver` is called, arguments is in fact empty. But if you read a bit further, you'll see that `resolver` calls itself recursively (indirectly, via the anonymous function it returns), and does in fact pass arguments. So you can't just start off with an empty array each time. You need to make sure you're taking into account any arguments that were passed in. Does that make sense?



view as:

Legal | privacy