가능한 중복 :
Location of parenthesis for auto-executing anonymous JavaScript functions?
Is there a difference between (function() {…}()); and (function() {…})();?
Two ways of immediate call to anonymous function (function(d){ }()); and (function(x){ })();자바 스크립트 익명 함수 - 정의
선언하고 익명 함수를 호출 주어진 두 가지 방법 사이에 차이가 있습니까?
옵션 1 :
(function(){
console.log('Declare and call anonymous function');
})();
옵션 2 : 그것은 내가 그 차이를 이해할 수 없었다 evaluated.But되면
(function(){
console.log('Declare and call anonymous function');
}());
두 함수가 호출된다.
옵션 1은 함수를 호출하기 전에 정의되고 사용할 수 있음을 보증합니다. 아마 그것은 호환성을 위해 그렇게 행해진 다 (브라우저는 까다로운 함수 정의 상황에서 아주 다르게 행동 할 수있다). – Brendan
옵션 3 :! function() {console.log ('익명 함수 선언 및 호출'); }() – GillesC
내 대답을 참조하십시오 http://stackoverflow.com/a/3783287/5445 실용적인 차이가 * 문법 * 수준에서만 차이가 있습니다. – CMS