js里使用单例模式
js
export default class HistoryKeyword {
constructor() {
if(typeof HistoryKeyword.instance === 'object'){
return HistoryKeyword.instance
}
HistoryKeyword.instance = this
return this
}
}
在类里面的constructor里加上这样的代码,使用的时候,不管new多少次,都是操作的同一个对象