Created
November 2, 2018 21:10
-
-
Save gloony/4411def2fc69ffcbdf56810b9f53784a to your computer and use it in GitHub Desktop.
Set var with localStorage or in array if not available
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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