💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# 单例模式 ES5 ~~~ function Storage (){} Storage.getInstance = (function () { var instance = null return function () { if (!instance) { instance = new Storage() } return instance } }()) Storage.prototype.getItem = function (name) { return localStorage.getItem(name) } Storage.prototype.setItem = function (name, value) { return localStorage.setItem(name, value) } ~~~ <br> ES6 ~~~ class Singleton { constructor () { this.instance = null } static getInstance () { if (!this.instance) { this.instance = new Singleton() } return this.instance } getItem (name) { return localStorage.getItem(name) } setItem (name, value) { return localStorage.setItem(name, value) } } ~~~