Immediately invoked function expression: Difference between revisions

Content deleted Content added
m Reverted edits by 27.34.104.75 (talk) (HG) (3.4.7)
Fixing URL (reference)
Line 1:
 
An '''immediately invoked function expression''' (or '''IIFE''', pronounced "iffy")<ref name=Alman>{{cite web |last=Alman |first=Ben |title=Immediately Invoked Function Expressions |url=http://benalman.com/news/2010/11/immediately -invoked-function-expression/ |date=15 November 2010 |accessdate=418 FebruaryJanuary 20132019 |archive-url=https://web.archive.org/web/20171201033208/http://benalman.com/news/2010/11/immediately invoked-function-expression/ |archive-date=1 December 2017 |dead-url=no}}</ref> is a [[JavaScript]] [[Programming idiom|programming language idiom]] which produces a [[scope (computer science)|lexical scope]] using JavaScript's [[function scoping]]. Immediately invoked function expressions can be used to avoid [[JavaScript syntax#Scoping and hoisting|variable hoisting]] from within blocks, protect against polluting the [[Global variable|global environment]] and simultaneously allow public access to methods while retaining privacy for variables defined within the function. This concept has been referred to as a '''self-executing anonymous function''',<ref>{{cite book |last=Resig |first=John |title=Pro JavaScript Techniques |year=2006 |publisher=Apress |isbn=978-1-4302-0283-7 |page=29}}</ref> but Ben Alman introduced the term IIFE as a more semantically accurate term for the idiom, shortly after its discussion arose on comp.lang.javascript.<ref name=Alman/><ref name=Osmani>{{cite book |last=Osmani |first=Addy |title=Learning JavaScript Design Patterns |year=2012 |publisher=O'Reilly |isbn=978-1-4493-3487-1 |page=206}}</ref><ref>{{cite news |last=Baagoe |first=Johannes |title=Closing parenthesis in function's definition followed by its call |url=https://groups.google.com/forum/#!topic/comp.lang.javascript/tjVn1NjGDN8%5B1-25%5D |accessdate=19 April 2010}}</ref>
 
== Usage ==