Public Group

This topic is 2569 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

In my index.html, I use the regular script tag to load in .js files.

The problem I guess is that one js file is not seeing a the constructor for another object which is located is another js file. For example :

//foo.js
f = function(){ var o = new Bar(...); }
//Bar.js
var Bar = { name: "Bar" };
//index.html
<script /* load in bar.js */ >
<script /* load in foo.js */ >

The error says that Bar is not a constructor?

I am unsure on how to solve this problem, because I haven't used js much. Any advice? Also foo and bar is just an example but the actual
files are much more longer and there are more than 2

##### Share on other sites
Bar isn't a constructor, it's an object. If you want Bar to be a constructor, it should be:

function Bar() { this.name = "Bar"; }

##### Share on other sites
Sorry that was a typo, in the actual code it is defined as the constructor. Anyways I fixed the problem. The problem was that the files weren't getting loaded completely. So I had to put the link tag at the bottom of the file for it to do proper linking and loading.

• 17
• 11
• 15
• 9
• 49
• ### Forum Statistics

• Total Topics
631393
• Total Posts
2999774
×