【发布时间】:2014-02-02 01:07:44
【问题描述】:
对于我在 SO 上回答的上一个问题,我制作了以下库。
(function(){
var LS = function(){
return new LS.fn.init();
};
LS.fn = LS.prototype ={
//Check to see if the browser suports LocalStorage
init : function(){
this.ls = (typeof(Storage)!=="undefined") ? false : true;
return this;
}
}
LS.fn.init.prototype = LS.fn;
LS.fn.init.prototype = {
set : function(name, val){
if(this.ls) localStorage.setItem(name, val);
},
get : function (name){
if(this.ls) return localStorage.getItem(name);
},
remove : function(name){
if(this.ls) localStorage.removeItem(name);
},
test: function(){
alert("hi")
}
}
window.LS = window.ls = LS;
})();
直到最近,这一切都很好。
我收到如下错误:
LS.set("foo", "bar"); // Error: undefined is not a function...
即使是下面的代码也会报错:
LS.test();
为什么这停止工作了?
谢谢。
注意:以前,我有一个错字,但现在我已经修正了它,它仍然不起作用。
【问题讨论】:
-
你确定
LS.fn = LS.protorype ={是正确的吗? -
protorype != 原型
-
@stewart715 谢谢,我没注意到。
标签: javascript debugging error-handling local-storage