Open weijiyang opened 4 years ago
class Single {
constructor (name) {
this.instance = null
this.name = name
}
static foo (name) {
if(!this.instance) this.instance = new Single(name)
return this.instance
}
}
var a = Single.foo('name1')
var b = Single.foo('name2')
console.log(a === b)