Skip to content

Instantly share code, notes, and snippets.

@JSila
Created June 26, 2015 22:33
Show Gist options
  • Save JSila/9385d86415eaa1de38b8 to your computer and use it in GitHub Desktop.
Save JSila/9385d86415eaa1de38b8 to your computer and use it in GitHub Desktop.
this helps with saving and retriving values other than strings from localStorage.
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