Skip to content

Instantly share code, notes, and snippets.

@juliocesar
Created April 18, 2011 23:19
Show Gist options
  • Save juliocesar/926500 to your computer and use it in GitHub Desktop.
Save juliocesar/926500 to your computer and use it in GitHub Desktop.

Revisions

  1. juliocesar revised this gist Apr 19, 2011. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions best-localStorage-polyfill-evar.js
    Original file line number Diff line number Diff line change
    @@ -4,11 +4,10 @@

    // if (!('localStorage' in window)) {
    if (!Modernizr.localstorage) {
    var undef;
    window.localStorage = {
    _data : {},
    setItem : function(id, val) { return this._data[id] = String(val); },
    getItem : function(id) { return this._data.hasOwnProperty(id) ? this._data[id] : undef; },
    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 = {}; }
    };
  2. juliocesar revised this gist Apr 18, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion best-localStorage-polyfill-evar.js
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ if (!Modernizr.localstorage) {
    window.localStorage = {
    _data : {},
    setItem : function(id, val) { return this._data[id] = String(val); },
    getItem : function(id) { return data.hasOwnProperty(id) ? data[id] : undef; },
    getItem : function(id) { return this._data.hasOwnProperty(id) ? this._data[id] : undef; },
    removeItem : function(id) { return delete this._data[id]; },
    clear : function() { return this._data = {}; }
    };
  3. juliocesar revised this gist Apr 18, 2011. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions best-localStorage-polyfill-evar.js
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,7 @@

    // if (!('localStorage' in window)) {
    if (!Modernizr.localstorage) {
    var undef;
    window.localStorage = {
    _data : {},
    setItem : function(id, val) { return this._data[id] = String(val); },
  4. juliocesar revised this gist Apr 18, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion best-localStorage-polyfill-evar.js
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ if (!Modernizr.localstorage) {
    window.localStorage = {
    _data : {},
    setItem : function(id, val) { return this._data[id] = String(val); },
    getItem : function(id) { return this._data[id]; },
    getItem : function(id) { return data.hasOwnProperty(id) ? data[id] : undef; },
    removeItem : function(id) { return delete this._data[id]; },
    clear : function() { return this._data = {}; }
    };
  5. juliocesar revised this gist Apr 18, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion best-localStorage-polyfill-evar.js
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@
    if (!Modernizr.localstorage) {
    window.localStorage = {
    _data : {},
    setItem : function(id, val) { return this._data[id] = val; },
    setItem : function(id, val) { return this._data[id] = String(val); },
    getItem : function(id) { return this._data[id]; },
    removeItem : function(id) { return delete this._data[id]; },
    clear : function() { return this._data = {}; }
  6. juliocesar revised this gist Apr 18, 2011. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions best-localStorage-polyfill-evar.js
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,7 @@
    // 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 : {},
  7. juliocesar created this gist Apr 18, 2011.
    13 changes: 13 additions & 0 deletions best-localStorage-polyfill-evar.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    // 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 (!Modernizr.localstorage) {
    window.localStorage = {
    _data : {},
    setItem : function(id, val) { return this._data[id] = val; },
    getItem : function(id) { return this._data[id]; },
    removeItem : function(id) { return delete this._data[id]; },
    clear : function() { return this._data = {}; }
    };
    }