Skip to content

Instantly share code, notes, and snippets.



Last active Jan 2, 2018
What would you like to do?
A simple storage object in JavaScript using localStorage.
var Storage = {
_cache: {},
get: function (key) {
if (!this._cache[key]) {
this._cache[key] = localStorage[key];
return this._cache[key];
set: function (key, value) {
this._cache[key] = value;
sync: function () {
for (var key in this._cache) {
if (this._cache.hasOwnProperty(key)) {
localStorage[key] = this._cache[key];

This comment has been minimized.

Copy link
Owner Author

@louisstow louisstow commented May 20, 2013


  • Storage.get(key) - Return the saved item by key.
  • Storage.set(key, value) - Saved an item by key.
  • Storage.sync() - Sync all new data to localStorage. Do not use this method during gameplay.
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.