最近维护公司的老项目,项目采用公共js文件储存公共数据,这里提取关键代码解析一下。
下面是代码片段:
function KfitUserCache() {
var _oUserCache = new Object()
this.setCacheData = function (sKey,sValue) { // 存储数据
return _oUserCache.set(sKey,sValue);
};
this.getCacheData = function (sKey) { // 获取数据
return _oUserCache.get(sKey);
};
}
if (!window.KUC) {
window.KUC = new KfitUserCache()
}