28 September 2019

Tạo class trong Typescript constructor sử dụng Object.assign

Tạo mới class và constructor
2019
export class UserInfoModel
{
 guid: string;
 uid: string;
 
 first_name: string;
 last_name: string;

 email: string;
 zipcode: string;

 password: string;

 constructor(obj: any = null)
 {
  if(obj != null)
  {
   Object.assign(this, obj);
  }
 }
}

Tạo mới đối tượng
2019
public user: UserInfoModel = new UserInfoModel({guid: "D21ds12x", 
  uid: "cust2dsa12dsa", 
  first_name: "John", 
  last_name: "Doe", 
  email: "email@email.com", 
  zipcode: 10283,
  password: "Idasn2x2#"});

0 nhận xét:

Post a Comment

 

BACK TO TOP

Xuống cuối trang