2012-10-08 38 views
0

我得到一個類(SiteLoader),其特性之一是另一個類(LocalStorage_Helper)。JavaScript的 - (物體)沒有定義

我測試的小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> 
  • 爲什麼我確實收到錯誤?
  • 我需要以不同的方式啓動LocalStorage_Helper嗎?

回答

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> 
+0

哦,所以即使我在js文件中對它進行引用,我仍然需要將它鏈接到html文件中? – samy

+0

該文件中的引用與JavaScript無關。這是你的編輯器用於智能感知的東西嗎? – epascarello

+0

是的,這是有道理的,即時通訊使用視覺工作室。有沒有辦法在其他js文件中引用js文件,所以我不需要在html中鏈接它們? – samy