【发布时间】:2021-11-10 15:16:38
【问题描述】:
我有许多模型(它们是 javascript 类)为我的数据库保存名称,还有它的类型。有没有一种方法可以创建一个新用户,而不必在构造函数中调用所有这些属性?
class User {
name: string;
email: string;
password: string;
constructor(values: User) {
this.name = values.name;
this.email = values.email;
this.password = values.password;
// I don't want to call this.name, this.email, ... Since this User model is relatively small, but I have models with hundreds of attributes
}
}
【问题讨论】:
标签: javascript typescript class constructor