Forked from juliocesar/best-localStorage-polyfill-evar.js
Created
March 27, 2019 09:23
-
-
Save parserbot/7ec906ad6581c9f0c3459d5ad6a562ac to your computer and use it in GitHub Desktop.
This is the best localStorage polyfill in the world
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
| // I mean, seriously, localStorage is supported even by your mum. How about instead of | |
| // casing the feature out, you give users in-memory (stale) storage instead? | |
| // If they close your application, they deserve to lose data anyway. | |
| // if (!('localStorage' in window)) { | |
| if (!Modernizr.localstorage) { | |
| 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