Getter Setter LocalStorage HTML5
We know localStorage is useful for something that we think possible temporary, and place it on user browser. In large project we could bit dizzy what variables that we already use, and what value of that. We could write it like usual, but it waste time. Here I share short-time-cut for manage your localStorage.
/* ===== Variables ===== */
var local = localStorage;
var username = "user";
/* ===== Variables ===== */
/* ===== Function ===== */
function setLocal(key, value){
local.setItem(key, value);
}
function getLocal(key){
return local.getItem(key);
}
/* ===== Function ===== */
We place that script in general script JS, which load on every page.
I make sample using it : http://jsfiddle.net/danzkusuma/Z2HR6/
Thanks
Written by Fendy Kusuma Wardhana
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Html5
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#