2

To be honest, firstly I thought I could easily find answer in Google, but strange, there are very little information about it.

Could anybody explain, what does this code do? What is the advantage (purpose) of using this technique?

(function(document) {
  ...
}(document));
user90726
  • 939
  • 1
  • 8
  • 28

1 Answers1

3

This is an Immediately-Invoked Function Expression (IIFE) which is basically a function that is declared and called all in one go. It's purpose is to encapsulate logic without muddying up the global namespace (any variables that you declare in that function are only visible in the function). You can find more information here, or just Google IIFE.

Adrian Theodorescu
  • 11,664
  • 2
  • 23
  • 30