前端JS的面向对象写法还是挺好玩的—class继承、实现

class FormDataDTO1 {
  id;
  name;
  sex;
  remark;
}
class FormDataDTO2 extends FormDataDTO1 {
  age;
  address;
}

const formData1 = new FormDataDTO1();
const formData2 = new FormDataDTO2();

const obj1 = {
  id: 1,
  name: "alee",
  sex: "男",
}

Object.keys(obj1).forEach(key => {
  formData1.append(key, obj1[key]);
})

 

posted @ 2023-05-30 15:57  RHCHIK  阅读(18)  评论(0编辑  收藏  举报