You can access your method using your IIFE to return (or increase) a global variable.
You can do it as follows:
var globalObject = (function (theObject, $) { if (theObject.theMethod) { return theObject; } var message = 'theMethod called'; theObject.theMethod = function () { alert(message); }; return theObject; })(globalObject || {}, jQuery); globalObject.theMethod();
The sample we use is a little better.
We have one global object (for example, a namespace), and we add modules to it by importing js files containing IIFE.
Each IIFE adds a new module to one global entity.
This makes our entire project have only one global object that can arbitrarily use any of our modules, including a file.
I recommend checking out this article, which is a good discussion of the JavaScript module template:
jahroy
source share