function Session() { var game = JSON.parse(localStorage.getItem('game')); return { hasSavedGame: hasSavedGame, save : save }; function hasSavedGame() { return game != undefined; } function update(state) { game = state; } function save() { localStorage.setItem('game', game); } }