2013-06-21 64 views
0

我有一個像周圍50個對象:添加功能,對象參數

object[0].one = something; 
object[0].two = else; 
object[0].options = whatever; 

不知道該怎麼形容,但他們每個人都有子參數。我想補充一點,我將手動添加,只有那些我想太多,像這樣一個附加參數:

object[15].condition = function() { if (something) { then do something; } } ; 
//and then later on in a function do 
if (this.condition) { 
this.condition; 
} 

,但我無法得到它的工作=(是這樣的任何可能的幫助是什麼?不勝感激。

+1

如何'對象[15]'轉成'this'? – Musa

+1

如果你調用一個函數是一個對象的屬性,你還必須加括號。'this.condition ()'而不是'this.condition'。 – bfuoco

+0

令人驚訝的是,bfuoco。我不明白爲什麼當我至少嘗試了其他所有東西時,我至少不會嘗試這些東西,出於某種原因,我確信那不會工作..該死的。多麼浪費時間和一個問題,對於麻煩抱歉。非常感謝,如果不是評論,本來可以選擇這個作爲最佳答案,再次感謝。 –

回答

2
if (this.condition) { 
    this.condition(); 
}