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
  • 5,535
  • 5
  • 36
  • 57

3 Answers3

12

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

Community
  • 1
  • 1
Oded
  • 477,625
  • 97
  • 867
  • 998
4

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,334
  • 7
  • 99
  • 123
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
  • 65,559
  • 18
  • 128
  • 140