Created
June 26, 2015 22:33
-
-
Save JSila/9385d86415eaa1de38b8 to your computer and use it in GitHub Desktop.
this helps with saving and retriving values other than strings from localStorage.
This file contains 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
Storage.prototype.getItem = function(key) { | |
try { | |
return JSON.parse(this[key]); | |
} catch (error) {} | |
return this[key]; | |
} | |
Storage.prototype.setItem = function(key, value) { | |
this[key] = (typeof value == 'string') ? value : JSON.stringify(value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment