Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Undefined object in external file

Status
Not open for further replies.

rylle2000

Programmer
May 23, 2002
4
SE
Hi I'm writing a script that uses an object (contstructed by myself) from antother .js file. The first line in the script just construct an instant of the object. Or should do, more correctly. IE 5.5 keeps saying that "'Matches' is undefined". Here's snippets of the code:


***********************
matches.js:
***********************
[tt]
/* Objekt för hantering av matcherna från Databasen */

function Matches(year, month) {
this.matches = new Array;
this.dateStack = new Array;
this.year = year;
this.month = month;
this.addMatch = mAddMatch;
this.getMatches = mGetMatches;
}

[/tt]
... (more code follows in the file)


***********************
javascript-test.html
***********************
[tt]
<html>
<head>
<title> JavaScript - test </title>

<script language=&quot;JavaScript&quot; src=&quot;matches.js&quot;></script>
<script language=&quot;JavaScript&quot;>

function init() {
//
var decMatches = new Matches(2002,12);
decMatches.addMatch(5,&quot;A&quot;,&quot;18:00&quot;,&quot;Seriematch&quot;,&quot;Mossens IP&quot;,&quot;Mossens IP&quot;,&quot;St Jakob&quot;);

decMatches.addMatch(5,&quot;C&quot;,&quot;17:00&quot;,&quot;Seriematch&quot;,&quot;Heden&quot;,&quot;Heden 7&quot;,&quot;Andra BK&quot;);
matches = decMatches.getMatches(2002+12+5+&quot;&quot;);


str = &quot;&quot;;

for (var i=0; i<matches.length; i++) {
var tempMatch = matches;
str = str + &quot;|&quot; + tempMatch.team + &quot;|&quot; + tempMatch.time + &quot;|&quot; + &quot;<br>&quot; +
&quot;|&quot; + tempMatch.type + &quot;|&quot; + tempMatch.place + &quot;|&quot; + &quot;<br>&quot; +
&quot;|&quot; + tempMatch.field + &quot;|&quot; + tempMatch.opponent + &quot;|<br><br>&quot;;
}

document.write(str);
}

</script>
[/tt]
... (more code follows in the file)

Anyone got an idéa what's wrong?
 
Maybe matches.js is not in the same folder with javascript-test.html
 
I had a quite long block comment in the end of the .js-file (commenting other objects) that the javascript interpreter apparently didn't like very much.

There might have been some bracket or something in there that wasn't commented.
A javascript CAN end with a block comment, right? :)
 
/*
certainly.

I believe that if the function defining the object has an error in, that the interpreter might report an undefined object error.

For example, if mAddMatch() were in the comment block it might cause Matches() to be undefined.
*/
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top