javascript
复制代码
function User(name, age, career, work) {
this.name = name;
this.age = age;
this.career = career;
this.work = work;
}
function Factory(name, age, career) {
let work;
switch (career) {
case "程序员":
work = ["写逻辑", "写样式"];
break;
case "老师":
work = ["教学生", "带学生"];
break;
default:
break;
}
return new User(name, age, career, work);
}
let aaa = Factory("张三", 18, "程序员");//{name: "张三",age: 18,career: "程序员",work:["写逻辑", "写样式"]}
let bbb = Factory("李四", 28, "老师");//{name: "李四",age: 28,career: "老师",work:["教学生", "带学生"]}
console.log(aaa, bbb);