User Tools

Site Tools


java-script:iife-programming-pattern

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

java-script:iife-programming-pattern [2023/08/10 00:55] – created odeftajava-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, modular piece of code that is easy to maintain, while still providing a clear and concise interface for other developers to interact with. By using an IIFE in this way, you can create a well-structured, modular piece of code that is easy to maintain, while still providing a clear and concise interface for other developers to interact with.
 +
 +===== 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's purpose.
 +
 +Example of a named IIFE:
 +<code javascript>
 +(function namedIIFE() {
 +  console.log('This is a named IIFE');
 +})();
 +</code>
 +
 +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**, as the name is scoped to the function itself.
 +</note>
  
 ===== IIFE and ES6 ===== ===== IIFE and ES6 =====
java-script/iife-programming-pattern.1691618109.txt.gz · Last modified: 2023/08/10 00:55 by odefta