可能重複:
What's the role of the parentheses in the following piece of code?在下面的代碼末尾做什麼()?
var dummy = (function (name) {return name;}(dummy || {}));
dummy.foo = (function(s){
this.s = s;
return true;
})();
好了,所以我不熟悉OO的Javascript,但我知道一點點。我是否正確地說這是foo的構造函數? ()在最後做了什麼?爲什麼功能()也在parentesis?之間有一些代碼,但爲了簡單起見,我將它們取出。以上內容與以下相同嗎?
dummy.foo = function(s){
this.s = s;
return true;
};
我想看看一些代碼別人寫不和我沒有在OO方面很多經驗,所以我感到很困惑,什麼是什麼。我甚至不能找出哪些是構造
有趣的臉(); – Ben
你從哪裏得到這些可怕的例子? – ChaosPandion
@Ben哈哈,看起來像「大叫和眨眼」 – Phil