const Storage = (function(){
return{
set:function(key,value,expireSeconds){
localStorage[key] = JSON.stringify({
value,
expired:expireSeconds === undefined ? undefined :Date.now() + 1000*expireSeconds
})
},
get:function(key){
if(localStorage[key] === undefined){
return
}
let object = JSON.parse(localStorage[key])
if(object.expired === undefined || Date.now() < object.expired){
return object.value
}else{
delete localStorage[key]
}
}
}
})()
网友评论