关于javascript:JavaScript的设计模式

引言

一.工厂模式

工厂模式大抵能够分为三类:简略工厂模式工厂办法模式形象工厂模式

  1. 简略工厂模式
    简略工厂模式顾名思义就是简略

     class GeGe {
         name = 'cxk';
         age = 2.5;
         getName() {
             return this.name;
         }
         getAge() {
             return this.age + '岁';
         }
     }
     const gege = new GeGe();
     console.log(gege.getAge(), gege.getName());
  2. 工厂办法模式
  3. 形象工厂模式

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理