Sign in to follow this  

javascript: loading in external js file problem

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 :

f = function(){ var o = new Bar(...); }
var Bar = { name: "Bar" };
<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 this post

Link to post
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.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this