Search code examples
javascriptiife

IIFE inside an IIFE. Issues? Performance?


My library is an an IIFE like this:

(function () {

    win.global = global;

}());

inside this library I have my code organized into modules which also look like this:

var foo1 = (function () {
    var publik = {},
        private = {};
    return publik;
}());
._extend(global, foo1);

where there is a foo for each module.

Are there any issues with having IIFEs inside an IIFE?

Most of the major libraries are encapsulated in an IIFE, but from there they organize their code into simple object literals NOT IIFEs.

That's why I'm asking/curious.

I do this because I like my modules to have private members and this pattern allows this.


Solution

  • There is nothing wrong with that.

    Javascript function expressions can be nested arbitrarily deeply.