6

Possible Duplicate:
Explain JavaScript’s encapsulated anonymous function syntax

i don't understand completely what this does, so i wanted to look it up in google but I didn't find anything and realized that I don't know its name; so my question is: What is the name of this construction (?) :

( function ( ... ) {} )( jQuery, window, document );

Thanks in advance guys.

Community
  • 1
  • 1
tmuecksch
  • 6,222
  • 6
  • 40
  • 61

3 Answers3

11

It is a Self Executing Anonymous Function, or Immediately Invoked Function Expression (IIFE), as others also answered.

Community
  • 1
  • 1
Oded
  • 489,969
  • 99
  • 883
  • 1,009
3

It's called a Self Executing Anonymous Function.

The purpose is to control scope so you aren't referencing globals or poluting the global namespace.

Josh
  • 44,706
  • 7
  • 102
  • 124
2

It's an Self Executing Anonymous Function.

You can use these to prevent polluting or accessing the global (window) namespace with new vars.

Cerbrus
  • 70,800
  • 18
  • 132
  • 147