我得到了一个类(SiteLoader),它的一个属性是另一个类(LocalStorage_Helper)。
我正在测试我制作的小API,但我收到“LocalStorage_Helper未定义”错误,我不明白为什么。
这是使用LocalStorage_Helper的类和使用该对象的部分:
/// <reference path="localSotrageHelper.js" /> // -- refrence to the js file
function SiteLoder(_storageName) {
this.theList = new Array();
this.storageHelper = new LocalStorage_Helper(_storageName); --HERE is where i get the error
}
//Add_theList_ToStorage
SiteLoder.prototype.Add_theList_ToStorage = function () {
this.storageHelper.AddItem(this.theList);
}
//Get_theList_FromStorage
SiteLoder.prototype.Get_theList_FromStorage = function () {
this.theList = this.storageHelper.GetItem();
}
我正在使用像这样的SiteLoader,在html文件中:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="SiteLoader.js" type="text/javascript"></script>
<script>
var Loader = new SiteLoder("sites"); // Error is thrown when i open the html
function setStoregeTest() {
Loader.PupolateListFrom_UL("list");
Loader.Add_theList_ToStorage();
}
function showStoregeTest() {
Loader.Get_theList_FromStorage();
Loader.WriteListTo_UL("list");
}
</script>
</head>
<body>
<ul id="list" contenteditable="true">
<li></li>
</ul>
<input type="button" value="set" onclick="setStoregeTest()" />
<input type="button" value="get" onclick="showStoregeTest()" />
</body>
</html>
答案 0 :(得分:2)
您的html标记中没有包含LocalStorage_Helper.js。
<head>
<title></title>
<script src="LocalStorage_Helper.js" type="text/javascript"></script>
<script src="SiteLoader.js" type="text/javascript"></script>