我有这个代码:
Storage.prototype.setObj = function(key, obj) {
return this.setItem(key, JSON.stringify(obj))
}
Storage.prototype.getObj = function(key) {
return JSON.parse(this.getItem(key))
}
function onReady() {
if (localStorage["piecesArray"]) {
piecesArray = new Array();
piecesArray.length = 0;
piecesArray = localStorage.getObj("piecesArray");
} else {
piecesArray = new Array();
}
can = document.getElementById('myCanvas');
ctx = can.getContext('2d');
img = new Image();
img.onload = onImage1Load;
img.src = "http://www.niagaraparks.com/images/wallpaper/niagarafalls_640x480.jpg";
}
我想将游戏状态保存在 中localStorage
,刷新页面后我想刷新游戏状态。
我究竟做错了什么?