0

I got a class (SiteLoader) that one of its properties is another class(LocalStorage_Helper).

I'm testing the small API I made, but I'm getting "LocalStorage_Helper is not defined" error, and I have no idea why.

Here is the class that uses LocalStorage_Helper and the parts that are using the object:

/// <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();
}

I'm using SiteLoader like so, on the html file:

<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>
  • Why I do get an error?
  • Do I need to initiate LocalStorage_Helper in a different way?

1 Answer 1

2

You are not including LocalStorage_Helper.js in your html markup.

<head>
    <title></title>
    <script src="LocalStorage_Helper.js" type="text/javascript"></script>
    <script src="SiteLoader.js" type="text/javascript"></script>
Sign up to request clarification or add additional context in comments.

4 Comments

oh, so even if i make a refrence to it in the js file, i still need to link it in the html file?
That reference in that file has nothing to do with JavaScript. That is something your editor is using for intellisense?
yeah that make sense, im using visual studio. is there a way to refrence js files inside other js file, so i wont need to linked them inside the html?
Not with JavaScript. You can look into libraries like require.js or make a build system that combines javascript files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.