未定义javascript-(对象)
我得到了一个类(SiteLoader),它的一个属性是另一个类(LocalStorage\u Helper) 我正在测试我制作的小API,但是我得到了“LocalStorage\u Helper未定义”错误,我不知道为什么 下面是使用LocalStorage\u Helper的类以及使用该对象的部分:未定义javascript-(对象),javascript,Javascript,我得到了一个类(SiteLoader),它的一个属性是另一个类(LocalStorage\u Helper) 我正在测试我制作的小API,但是我得到了“LocalStorage\u Helper未定义”错误,我不知道为什么 下面是使用LocalStorage\u Helper的类以及使用该对象的部分: /// <reference path="localSotrageHelper.js" /> // -- refrence to the js file function SiteL
/// <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();
}
//--引用js文件
函数SiteLoder(_storageName){
this.theList=新数组();
this.storageHelper=newlocalstorage\u Helper(\u storageName);--这里是我得到错误的地方
}
//将列表添加到存储中
SiteLoder.prototype.Add_theList_ToStorage=函数(){
this.storageHelper.AddItem(this.theList);
}
//从存储器中获取列表
SiteLoder.prototype.Get_theList_FromStorage=函数(){
this.theList=this.storageHelper.GetItem();
}
我在html文件上使用SiteLoader,如下所示:
<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>
var Loader=new SiteLoder(“站点”);//打开html时引发错误
函数setStoreGetTest(){
装载机。从_UL(“列表”);
加载程序。将列表添加到存储();
}
函数showStoregeTest(){
Loader.Get_theList_FromStorage();
加载程序。写入列表(“列表”);
}
- 为什么我会出错
- 我是否需要以不同的方式启动LocalStorage\u Helper
<head>
<title></title>
<script src="LocalStorage_Helper.js" type="text/javascript"></script>
<script src="SiteLoader.js" type="text/javascript"></script>
噢,所以即使我在js文件中引用了它,我仍然需要在html文件中链接它?该文件中的引用与JavaScript无关。这是你的编辑器用于intellisense的东西?是的,这是有意义的,我使用的是visual studio。有没有办法在其他js文件中引用js文件,这样我就不需要在html中链接它们了?不需要使用JavaScript。您可以查看require.js之类的库,或者创建一个结合javascript文件的构建系统。