Skip to content

Instantly share code, notes, and snippets.

@gloony
Created November 2, 2018 21:10
Show Gist options
  • Save gloony/4411def2fc69ffcbdf56810b9f53784a to your computer and use it in GitHub Desktop.
Save gloony/4411def2fc69ffcbdf56810b9f53784a to your computer and use it in GitHub Desktop.
Set var with localStorage or in array if not available
var locStore = {
internalVar: [],
get: function(name){
if(typeof localStorage!=='undefined') return localStorage.getItem(name);
else if(locStore.internalVar[name]!==undefined) return locStore.internalVar[name];
else return null;
},
set: function(name, value){
if(typeof localStorage!=='undefined') return localStorage.setItem(name, value);
else locStore.internalVar[name] = value;
},
unset: function(name){
if(typeof localStorage!=='undefined') localStorage.removeItem(name);
else delete myArray[name];
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment