Last Updated: February 25, 2016
·
1.3K
· danzkusuma

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