Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Extending Local Storage to save and get Objects
/**
* Extending the Local Storage Object to allow saving of objects.
*
* @param int|string key object key
* @param int|string value object value
* @return bool true|false
*/
Storage.prototype.setObject = function(key, value) {
this.setItem(key, JSON.stringify(value));
};
/**
* Extending the Local Storage Object to allow returning of saved objects.
*
* @param int|string key object key
* @return int|string value
*/
Storage.prototype.getObject = function(key) {
var value = this.getItem(key);
return value && JSON.parse(value);
};
@Xeoncross

This comment has been minimized.

Copy link

Xeoncross commented Jun 27, 2017

Doesn't handle exceptions like private browsing mode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.