多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# 单例模式 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) } } ~~~