Created
July 19, 2013 12:30
-
-
Save westonwatson/6038799 to your computer and use it in GitHub Desktop.
a simple in memory localStorage pollyfill
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
(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; | |
} | |
})()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
from the comments here: https://gist.github.com/juliocesar/926500, by @DmitryBaranovskiy