单例模式:只能调用一次 class
dellAnalyzer.ts
...// 将 constructor 变为私有属性private constructor() {}// 定义一个“锁”private static instanse: DellAnalyzer// 暴漏给外部的方法static getInstance() {// 一旦调用就不能够调用了if (!DellAnalyzer.instanse) {DellAnalyzer.instanse = new DellAnalyzer()}return DellAnalyzer.instanse}...
crowller.ts
...-const analyzer = new DellAnalyzer()+const analyzer = DellAnalyzer.getInstance()
之后,发现,在外部也可以调用到 crowller 实例的方法,但不希望别人调用,所以需要将 crowller 的方法设成私有属性(前面加:private)
