[Solved] Manually Invoke IIFE


The whole idea of the IIFE is that its an anonymous function that is immediately executed. So by definition, no there is no way to re-execute it.

With that said however, you can store the function expression to a global variable, and execute it. For example

window.my_iife = (function() { /* stuff */ });
window.my_iife();

Notice the slight difference in syntax compared to the traditional IIFE: ((function() {})());

By storing the function in window, you are able to access it later from either the developer console or anywhere else in your code. If you simply store it in a var, or declare it as function my_iife() { /* ... */ } somewhere you risk that var or function declaration itself being wrapped in an IIFE and thus being inaccessible. As an example, that scenario could occur if the file you declared your var/function in is part of a Sprockets manifest (such as application.js in Rails).

7

solved Manually Invoke IIFE