![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
设计模式
王绝天下-lnx
笨鸟先飞多飞!!
展开
-
前端常见的设计模式(TS和JS实现)——工厂模式
目录TS实现JS实现TS实现// 定义接口interface Vehicle{ move():void}// 汽车类class Car implements Vehicle{ public move():void{ console.log("The car is moving!") }}// 自行车类class Bicycle implements Vehicle{ public move():void{ console.log('T.原创 2020-11-25 09:07:33 · 467 阅读 · 0 评论 -
前端常见的设计模式(TS和JS实现)——单例模式
目录TS实现JS实现单例模式可能是最著名的设计模式之一。它是一种创建模式,因为它确保无论我们尝试实例化一个类多少次,我们都只有一个可用的实例。处理数据库连接之类的可以单例模式,因为我们希望一次只处理一个,而不必在每个用户请求时重新连接。TS实现class MyDBConn{ protected static instance:MyDBConn | null = null private id:number = 0 constructor(){ this.id原创 2020-11-24 19:29:25 · 720 阅读 · 0 评论