工厂模式

  1. function createPerson (name, age, job) {
  2. let o = new Object();
  3. o.name = name;
  4. o.age = age;
  5. o.job = job;
  6. o.sayName = function () {
  7. console.log(this.name)
  8. }
  9. return o
  10. }
  11. let person1 = createPerson(x,x,x)
  12. let person2 = createPerson(x,2,2)

构造函数模式

原型模式