Skip to content

Instantly share code, notes, and snippets.

@westonwatson
Created July 19, 2013 12:30
Show Gist options
  • Save westonwatson/6038799 to your computer and use it in GitHub Desktop.
Save westonwatson/6038799 to your computer and use it in GitHub Desktop.
a simple in memory localStorage pollyfill
(function (isStorage) {
if (!isStorage) {
var data = {},
undef;
window.localStorage = {
setItem : function(id, val) { return data[id] = String(val); },
getItem : function(id) { return data.hasOwnProperty(id) ? data[id] : undef; },
removeItem : function(id) { return delete data[id]; },
clear : function() { return data = {}; }
};
}
})((function () {
try {
return "localStorage" in window && window.localStorage != null;
} catch (e) {
return false;
}
})());
@westonwatson
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment