var lsc = function (dataid) { this.dataid = dataid; return this; }; lsc.prototype = { add: function (dataval) { this.dataval = dataval || []; localStorage.setItem(this.dataid, JSON.stringify(this.dataval)); }, get: function () { return JSON.parse(localStorage.getItem(this.dataid)); }, remove: function () { localStorage.removeItem(this.dataid); }, clear: function () { localStorage.clear(); } };
var newStorage = new lsc(newData); var getStorage = newStorage.get(newData)
function getsenderpush() { if(getStorage){ dosenderpush(getStorage) }else{ var param ={registerid:registerid,token:token,id:id} ,url='/kugou/public/mobile/sender/senderRoom'; return new Promise(function (resolve, reject) { $.get(url,param,function (data) { dosenderpush(data) //缓存开始 newStorage.add(data) resolve() }) }) } }