Created
August 6, 2013 02:00
-
-
Save rachelbaker/6161375 to your computer and use it in GitHub Desktop.
Extending Local Storage to save and get Objects
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
/** | |
* 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); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Doesn't handle exceptions like private browsing mode