ES6 的类中使用单例模式

阅读 54

2022-05-30

核心代码:



export default class ChartUtil {
static getInstace() {
if (!ChartUtil.instace) {
ChartUtil.instace = new ChartUtil();
console.log('新创建了一个实例');
return ChartUtil.instace;
}
console.log('复用之前的实例');
return ChartUtil.instace;
}

constructor() {
this.initChartLabel();
}

initChartLabel() {
this.lineChartStartLabel = '';
}


}

 

创建实例:

this.chartUtils = ChartUtils.getInstace();

 

效果图:

ES6 的类中使用单例模式_复用 


精彩评论(0)

0 0 举报