Difference between revisions of "Immediately-invoked function expression"
From Wiki @ Karl Jones dot com
Karl Jones (Talk | contribs) (Created page with "An '''immediately-invoked function expression''' (or '''IIFE''', pronounced "iffy") is a JavaScript design pattern which produces a Scope (computer science)|lexical...") |
Karl Jones (Talk | contribs) |
||
Line 19: | Line 19: | ||
* [https://en.wikipedia.org/wiki/Immediately-invoked_function_expression Immediately-invoked function expression] @ Wikipedia | * [https://en.wikipedia.org/wiki/Immediately-invoked_function_expression Immediately-invoked function expression] @ Wikipedia | ||
− | + | * [http://benalman.com/news/2010/11/immediately-invoked-function-expression/ Immediately-Invoked Function Expression (IIFE)] | |
+ | * [http://markdalgleish.com/2011/03/self-executing-anonymous-functions/ Self-Executing Anonymous Functions] | ||
[[Category:JavaScript]] | [[Category:JavaScript]] | ||
[[Category:Software engineering]] | [[Category:Software engineering]] |
Revision as of 08:01, 26 August 2016
An immediately-invoked function expression (or IIFE, pronounced "iffy") is a JavaScript design pattern which produces a lexical scope using JavaScript's JavaScript's function scoping.
Description
Immediately-invoked function expressions can be used to:
- Avoid variable hoisting from within blocks
- Protect against polluting the global environment
- Simultaneously allow public access to methods while retaining privacy for variables defined within the function
This pattern has been referred to as a self-executing anonymous function; Ben Alman introduced "IIFE" as a more semantically accurate term for the pattern, shortly after its discussion arose on comp.lang.javascript.