0
eggersa created
I was wondering why every javascript code is wrapped in a function like this:
(function () {
...
}();
I have never seen this before. Maybe there is a good idea behind this to keep going with this practice?
Thank you for your answer!
1 Answer(s)
-
0
Hi,
That's a very common pattern, known as Immediately-Invoked Function Expression (IIFE).
You can find many answer on the web, example: <a class="postlink" href="http://stackoverflow.com/questions/8228281/what-is-the-function-construct-in-javascript">http://stackoverflow.com/questions/8228 ... javascript</a>
In brief, this creates a local scope and prevents accidently declaring global variables/functions.