Last active
May 21, 2017 10:45
-
-
Save svapreddy/eeda4e8f6f4eafc69a09 to your computer and use it in GitHub Desktop.
This file contains 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
// Author : Prathap Reddy SV | |
var LStorage = (function () { | |
function LStorage() { | |
this.localStorage = JSON.parse(JSON.stringify(localStorage)); | |
// or new Function("return JSON.parse('" + JSON.stringify(localStorage) + "')")(); | |
} | |
LStorage.prototype.setItem = function (key, val) { | |
if(this.localStorage[key] == val) return; | |
this.localStorage[key] = val; | |
localStorage.setItem(key, val); | |
}; | |
LStorage.prototype.getItem = function (key, undef) { | |
var val = this.localStorage[key]; | |
return val; | |
}; | |
LStorage.prototype.removeItem = function (key) { | |
delete this.localStorage[key] | |
localStorage.removeItem(key); | |
return true; | |
}; | |
return LStorage; | |
})(); | |
// Usage | |
var Storage = new LStorage(); | |
Storage.setItem(keuy, val); | |
val = Storage.getItem(key); | |
Storage.removeItem(key); // returns true. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment