我有一个班级
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
}
}
如上所述,我想为property3
提供假值但property1
和property2
我将从实例化中获取它。我怎样才能做到这一点?
答案 0 :(得分:-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
}
}
有关TypeScript类https://basarat.gitbooks.io/typescript/docs/classes.html
的一些文档