2017-04-18 81 views
-3

初始化變量我有一個類單元測試給假值由構造

Test.ts:

class Test 
{ 
    public property1: string; 
    public property2: boolean; 
    constructor(property1, property2) 
    { 
      this.property1 = property1;//will get value while instantiation 
      this.property2 = property2;//will get value while instantiation 
      this.property3 = somevalue;//want to add fake value here 
    } 
} 

給出上面我想給一個假值property3property1和和property2我會從實例化中獲得它。我怎樣才能做到這一點?

+0

提示:使用「StackSnippet」工具,然後單擊'<>'按鈕來格式化碼。 – evolutionxbox

+0

請你可以編輯你的問題嗎?否則,在目前的狀態下,它很可能會被關閉。 – evolutionxbox

+0

@evolutionxbox如果你有答案給它否則不要在這裏哭。你不是孩子寫格式 – Nanda

回答

-1

我相信你正在努力宣佈property3成員。只需像你宣佈的其他屬性那樣做。其他可以使用屬性初始化,如果你想:在打字稿類

class Test 
{ 
    public property1: string; 
    public property2: boolean; 
    public property3 = somevalue; 
    constructor(property1, property2) 
    { 
      this.property1 = property1;//will get value while instantiation 
      this.property2 = property2;//will get value while instantiation 
    } 
} 

更多

一些文檔https://basarat.gitbooks.io/typescript/docs/classes.html

+0

感謝您的回覆。我不能移動這個屬性,因爲我只想在實例化的時候初始化它。所以我必須在那裏給出一個假值 – Nanda