function PageInfo(name, url, params){
this._name = name;
this._url = url;
this._params = params;
this._sessionId =
'';
}
function LocalStorageDeque(name, maxSize){
this._name = name;
this._items = [];
this._maxSize = maxSize||
1000;
var localItems = localStorage.getItem(
this._name);
if(localItems !=
null && localItems !=
''){
var oldItems =
JSON.parse(localItems);
if(oldItems.length >
0){
this._items = oldItems;
return;
}
}
localStorage.setItem(
this._name,
JSON.stringify(
this._items));
};
LocalStorageDeque.prototype.push =
function (item) {
cleanOverFlowItem(
this._items,
this._maxSize);
this._items.push(item);
localStorage.removeItem(
this._name);
localStorage.setItem(
this._name,
JSON.stringify(
this._items));
};
LocalStorageDeque.prototype.pop =
function () {
var ret =
this._items.pop();
localStorage.removeItem(
this._name);
localStorage.setItem(
this._name,
JSON.stringify(
this._items));
return ret;
};
LocalStorageDeque.prototype.clear =
function () {
this._items.clear();
localStorage.removeItem(
this._name);
};
function cleanOverFlowItem(itemArray, maxSize){
var len = itemArray.length;
if(len > maxSize){
itemArray.splice(
0, len - maxSize);
}
}
转载请注明原文地址: https://ju.6miu.com/read-1298622.html