function showAll(){ var keys=Object.keys(this.datastore);//调用Object.keys后返回的是key数组,然后下面的for in遍历的的key是数组下标,变量名起名为index你还好理解点 for(var index in keys){ document.write(keys[index] + "->" + this.datastore[keys[index]] + "<br />"); } } function clear(){////clear方法也是同样的错误,要么你就直接遍历this.datastore,不要调用Object.keys for(var key in this.datastore){ delete this.datastore[key]; } }
var keys=Object.keys(this.datastore);//调用Object.keys后返回的是key数组,然后下面的for in遍历的的key是数组下标,变量名起名为index你还好理解点
for(var index in keys){
document.write(keys[index] + "->" + this.datastore[keys[index]] + "<br />");
}
}
function clear(){////clear方法也是同样的错误,要么你就直接遍历this.datastore,不要调用Object.keys
for(var key in this.datastore){
delete this.datastore[key];
}
}
嗯,谢谢,还有个问题请问下,如果showAll和clear都用for in直接遍历this.datastore而不用Object.keys(),是否可以?
var o={};o[key]=value;////
this.datastore.push(o);
}