Skip to content

Instantly share code, notes, and snippets.

@axelav
Forked from juliocesar/best-localStorage-polyfill-evar.js
Last active January 23, 2018 00:14
Show Gist options
  • Save axelav/256fc206274464288ca1d75abeac6767 to your computer and use it in GitHub Desktop.
Save axelav/256fc206274464288ca1d75abeac6767 to your computer and use it in GitHub Desktop.
This is the best localStorage polyfill in the world
if (!('localStorage' in window)) {
window.localStorage = {
_data : {},
setItem : function(id, val) { return this._data[id] = String(val); },
getItem : function(id) { return this._data.hasOwnProperty(id) ? this._data[id] : undefined; },
removeItem : function(id) { return delete this._data[id]; },
clear : function() { return this._data = {}; }
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment