java-script:iife-programming-pattern
Differences
This shows you the differences between two versions of the page.
java-script:iife-programming-pattern [2023/08/10 00:55] – created odefta | java-script:iife-programming-pattern [2023/08/10 01:02] (current) – odefta | ||
---|---|---|---|
Line 79: | Line 79: | ||
Here IFE is used to encapsulate the entire library. It contains private variables and functions that are inaccessible from the outside, but it also defines a public API that is exposed through the returned object. \\ | Here IFE is used to encapsulate the entire library. It contains private variables and functions that are inaccessible from the outside, but it also defines a public API that is exposed through the returned object. \\ | ||
By using an IIFE in this way, you can create a well-structured, | By using an IIFE in this way, you can create a well-structured, | ||
+ | |||
+ | ===== Named IIFE functions ===== | ||
+ | |||
+ | Naming an IIFE function can be helpful for debugging, as the name can appear in stack traces and provide clarity about the function' | ||
+ | |||
+ | Example of a named IIFE: | ||
+ | <code javascript> | ||
+ | (function namedIIFE() { | ||
+ | console.log(' | ||
+ | })(); | ||
+ | </ | ||
+ | |||
+ | The name of the IIFE, in this case, is **namedIIFE**. | ||
+ | <note warning> | ||
+ | IIFE function name **is not accessible outside the function itself**, so it's primarily used for clarity within the code or debugging purposes. If you try to call namedIIFE() outside of its definition, it will result in a **ReferenceError**, | ||
+ | </ | ||
===== IIFE and ES6 ===== | ===== IIFE and ES6 ===== |
java-script/iife-programming-pattern.1691618109.txt.gz · Last modified: 2023/08/10 00:55 by odefta