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.

有帮助吗?

解决方案

There is nothing wrong with that.

Javascript function expressions can be nested arbitrarily deeply.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top