0
点赞
收藏
分享

微信扫一扫

ES6 的类中使用单例模式

勇敢乌龟 2022-05-30 阅读 53

核心代码:



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 条评论