java-script:iife-programming-pattern
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| java-script:iife-programming-pattern [2023/08/09 21:55] – created odefta | java-script:iife-programming-pattern [2025/01/02 18:22] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| 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: (external edit)
