在es6中,可以通过 static getInstance() 实现单例模式, 源代码: static getInstance(obj) { if (!this.instance) { this.instance = new myObject(obj); } return this.instance; }
但是obj是动态改变属性的,我做了如下改动:
static getInstance(obj) { if (this.instance) { delete this.instance; } this.instance = new myObject(obj); return this.instance; }
请问大家这样是否可以???有什么问题???谢谢