【发布时间】:2017-01-02 23:28:52
【问题描述】:
快速问题:我想创建一个具有一些多维属性的对象。
用户类具有性别、生日、身高等属性。
还有体重的多维属性,用户可以在其中添加他的新体重与当前日期。
interface weightData {
date: Date;
weight: number;
}
export class UserData {
sex: string;
location:string;
fokus:string;
birthdate:Date;
weight:Array<weightData> = [];
height:number;
constructor(sex:string, location:string, fokus:string, birthdate:Date, height:number, weight:number) {
let currentDate: Date = new Date();
this.sex = sex;
this.location = location;
this.fokus = fokus;
this.birthdate = birthdate;
this.height = height;
this.weight.push(
date: currentDate, //dont work
weight: 31 // dont work
);
}
}
我的 2 个问题:
1:构造函数的正确语法是什么?
2:创建为“权重”添加新值的方法的最佳方法是什么?
非常感谢。
【问题讨论】:
标签: angular typescript typescript2.0