Skip to content

Instantly share code, notes, and snippets.

@svapreddy
Last active May 21, 2017 10:45
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save svapreddy/eeda4e8f6f4eafc69a09 to your computer and use it in GitHub Desktop.
Save svapreddy/eeda4e8f6f4eafc69a09 to your computer and use it in GitHub Desktop.
// 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