可能重複:
What do parentheses surrounding a JavaScript object/function/class declaration mean?
What does this javascript syntax mean?
What does this 「(function(){});」, a function inside brackets, mean in javascript?這個語法是什麼意思? (函數(){//代碼})()
在下面的代碼正在執行匿名函數。
var a= 1;
var b =2;
(function() {
var b = 3;
a += b;
})();
document.write(a + " "+ b);
1)圍繞函數定義放括號是幹什麼用的?
2)在右括號之後放()
是做什麼的?
閱讀: http://stackoverflow.com/questions/593509/javascript-syntax-function-calls-and-using-parenthesis 希望這有助於:) – 2012-01-31 08:29:59