2017-04-18 71 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