0

Possible Duplicate:
Is there a difference between (function() {…}()); and (function() {…})();?

I have seen two slightly different ways of using the Self Executing Anonymous Function pattern.

1:

(function(){
    //do stuff
}())

2:

(function(){
    //do stuff
})();

Does the syntax difference have any implied effects that might not be obvious or are these two techniques exactly the same ?

Community
  • 1
  • 1
BentOnCoding
  • 27,307
  • 14
  • 64
  • 92
  • 2
    ...my search term was *"javascript difference between function parentheses"* It was the fourth result, among many other commonly asked questions about such inline function invocations. –  Aug 03 '12 at 17:07

2 Answers2

2

They are the same. People tend to rather use the first. I also think JSLint suggests the first version. I prefer the second. It's really up to you.

Christoph
  • 26,519
  • 28
  • 95
  • 133
1

that's absolute same

it called self-executed function

there are three pattern(but third pattern cannot return value)

one and two is your questions

one:

(function(){
    //do stuff
}())

two:

(function(){
    //do stuff
})();

and third is with '!' character

!function(){ 
    //do stuff
}();

good luck!

blueiur
  • 1,447
  • 1
  • 11
  • 17