. , name, id prefix. , getDepartmentList, prefix, Department. , .
, , prefix -property -, , Department. , , typescript. , , , , .
:
class Department
{
constructor(public name:string, public id:string){ }
get prefix(): string
{
return !isNaN(parseFloat(this.id)) ? "n" : "i" ;
}
}
function getDepartmentList(): Department[]
{
return [new Department("Dept 1", "1000")];
}
Department, .
typescript , .
:
class Department
{
name: string;
id:string;
constructor(name:string, id:string){
this.name = name;
this.id = id;
}
get prefix(): string
{
return !isNaN(parseFloat(this.id)) ? "n" : "i" ;
}
}